Is it possible to create a global listener for an exception in Ruby?
I want to catch all exceptions in my script for StateMachine::InvalidTransition so my application can respond with sending an email with the error.
Normally in Ruby, a rescue block is preceded by begin, but I want to have a central listener method that will catch all exceptions for the above mentioned exception.
Is this possible at all?
I really don't want to place
begin
# Do some stuff
rescue StateMachine::InvalidTransition => exception
# Send error in email message
end
inside every single event I have in my state_machine.
I want something similar to set_exception_handler() in PHP.