No responses? I was just curious to know what kind of error handling
people do. It seems to me that the try/catch/throw method is an
improvement to the old days of checking error returns and trying to pass
the right amount of error detail info upstairs to callers. I know how to
use eval and die handlers.
Do most serious Perl programmers use one method or another of handling
errors, and if so, what?
I use eval and a custom error object. The main problem I have with this is
that the eval is at the top level and so any module error messages which
don't provide a line number in the caller (as is the case with
DBD::Sybase) can be difficult to trace. Otherwise it works well. I define
some error codes in my Error object and trapping specific errors can be as
simple as
die MyApp::Error->new(<errorcode>) unless (...);
Also unforseen errors get trapped by the eval. $@ is a string not an
object when that happens, but is easily remedied.
Rich