Monkey patch Exception class

What I want to achieve is, is that I can hook into the Exception class
of Ruby so that I can trigger special logging events, when an exception
occurs.

I could easily define custom error classes, but I would like to take a
more general approach.

Does someone have advice on how to do this?

Thanks!

On May 14, 2013, at 16:12 , Sebastian Wy [email protected] wrote:

What I want to achieve is, is that I can hook into the Exception class
of Ruby so that I can trigger special logging events, when an exception
occurs.

or you can run with ruby -d

Ryan D. wrote in post #1109018:

On May 14, 2013, at 16:12 , Sebastian Wy [email protected] wrote:

or you can run with ruby -d

Hi!

This would theoretically be an option, but I would want to pack the
functionality into a Gem, so other users can hook it into their
applications, and thus this would not be an option.

So, this seems to work:

class Exception

def initialize(*args)
puts “initialize”
end

end

The text gets printed out on every exception. I don’t know how ugly this
solution is and especially how stable, but the functionality seems to be
given.