Perl Monk, Perl Meditation | |
PerlMonks |
comment on |
( [id://3333]=superdoc: print w/replies, xml ) | Need Help?? |
Yeah, don't do that. That isn't a feature of Perl that is discarding the error reason. That is bad coding that is explicitly discarding the error reason. Such code should look at least more like:
The feature of (modern) Perl that could discard an error reason goes more like this:
Which produces:
But all you have to do is add "-w" (such as to the "#!" line) to get:
But, yes, you lose programmatic access to inner error(s). But if you want programmatic access to errors, then you should be using structured exceptions and you get access to the inner error by having the outer exception store a reference to the inner exception. If you ever use eval, when it fails, you need to do at least one of the following things with the resulting value of $@:
Note that (3) is usually better done using structured exceptions or something like Errno. We actually have a __DIE__ handler (at $work) in order to log why the program is about to exit (we don't just redirect STDERR straight to the log file as we prefer log lines to be in a parsable format and to include a precise timestamp and some context information). Unfortunately, our old version of Perl has a bug with $^S so we can't reliably distinguish between exceptions that are about to be caught from exceptions that are about to cause the program to exit. So, for now, we have a flawed heuristic where exceptions that happen within a short time span of the program exiting are logged. I can tell you that it is easily very annoying to have caught exceptions being logged. Having a bunch of fatal-looking error messages that don't actually indicate any kind of problem sucks. I don't see any way for your idea of collecting all exceptions to produce more signal than noise. Actually, I don't even see how such an idea ever allows for an exception to be freed. So catching an exception just becomes a memory leak. - tye In reply to Re: eval error stack (noise)
by tye
|
|