In Rails.
Exception can rescue in controller class but in model class can not.
How to rescue exception in model?
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
You can do exception handling anywhere in a rails application, as it’s part of Ruby, not part of Rails. Wherever you want to catch errors, just wrap it as so:
Please note that you should always “rescue Exception” instead of just “rescue”. Just using “rescue” will only catch StandardError, which is a subclass of Exception (meaning something might get through that you don’t want to get through).
Also as usual, you can raise an exception by doing:
anywhere in your code, be it a model or controller.