in reply to Overwriting exit and similar

The easiest way to trap die is to just put everything in an eval block. Also see die for info about what you can do with $SIG{'__DIE__'}.

exit is a little trickier, but you might be able to set something up in an END block. (I've never tried, myself... I'm not sure what would happen if you did a goto in an END block). I'd think you'd be better off just removing calls to exit, or changing them to die where appropriate, if that's possible.