in reply to Re: (tye)Re: XML::Parser and the utf8 Pragma
in thread XML::Parser and the utf8 Pragma

Well, real signal handlers have their own problems that I won't go into here. One problem with both __WARN__ and __DIE__ handlers is that they are single-slot globals so if you want to use them then you had better hope that none of the modules you use had a use for them either or you are going to "bump heads".

Other than the above, __WARN__ handlers don't bother me and are an okay way to catching warnings. If you have new enough Perl, then I think you can instead use warnings.

If you just want your warnings and errors to end up in a log file, then I'd simply redirect STDERR and avoid all this fancy stuff!

__DIE__ handlers on the other hand have several design problems and the alternative, eval and $@, don't have these problems, so I always encourage the use of eval {...} in place of the __DIE__ handler. __DIE__ handlers also look deceptively easy so people often choose them over eval.

Some of the problems with __DIE__ handlers: They get called even inside eval so you run the risk of reporting errors that you shouldn't or of making non-fatal non-errors into fatal errors. Also, if you use eval (instead of a handler), you don't have these problem and you also don't have the problem of "bumping heads" with other modules that want to use eval.

Also, eval "..." has a (partially deserved) reputation for being "slow" so people are often shy to use eval {...}.

        - tye (but my friends call me "Tye")