uncaught exceptions

F

Florian Weber

hi!

is there a way to catch uncaught exceptions globally for a
ruby app? i would like to have some functionality executed (sending
a report email, etc) whenever a exception can not be caught..

thanks a lot!

ciao!
florian
 
P

Paul Brannan

is there a way to catch uncaught exceptions globally for a
ruby app? i would like to have some functionality executed (sending
a report email, etc) whenever a exception can not be caught..

The simplest way is to catch the exception at the topmost level of your
application.

If for some reason you cannot do that, you can use at_exit or END; the
uncaught exception will be in $! (worked for me in 1.6.8, 1.8.1 and
latest CVS -- didn't work in 1.8.0, though). However, unless you are
using latest CVS, the exception will be printed before the block is
called, so there's no way I know of using this mechanism to inhibit
printing the exception to stderr.

Paul
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,780
Messages
2,569,611
Members
45,276
Latest member
Sawatmakal

Latest Threads

Top