I have just barely gotten into Ruby / ROR but need to quickly write a class for handling errors and doing something with them. I’ve been able to find the important examples/tutorials for the rest of what I need but I’m having trouble finding what the best alternative to PHP’s “set_error_handler” is.
My goals are:
- I’d like to write a class that will capture any ruby-level errors automatically.
- I’d like for the class to also be called by the user when there are custom errors/exceptions to report.
I’d like this work for any ruby app, but my main focus is for ruby-on-rails applications as well. Thanks for your advice.
I think the closest equivalent in Rails is rescue_from – it allows you to specify code will catch any given exception (except some template errors – though there are ways round that). If you want, you could then hand it off to some other class. So I guess what you’d do in your case would be:
in app/controllers/application_controller.rb:
in lib/my_exception_handler.rb:
If that helps, let me know and I’ll dig out the link to how you catch template errors.