Question

This script:

use warnings FATAL => 'all';

warn 'warning';
die 'death';

...results in 'warning' getting logged, but doesn't die at that point, instead dying with 'death'.

I have a mod_perl module that overrides $main::SIG{__DIE__} to basically spit out die() messages to the browser during development, but it does not touch SIG{__WARN__}, so what is happening here?

This is on perl 5.10.1 on Windows Server 2003, with "-w" in PerlSwitches.

Was it helpful?

Solution 2

You misunderstood the purpose of the warnings pragma. It is there to emit a warning message for completely legal, but possibly wrong operations. Example:

use warnings;
my ($x, $y) = ("hello", "world");
say "same" if $x == $y;

Argument "world" isn't numeric…. We can make certain categories produce fatal errors with use warnings FATAL => $CATEGORY with categories like numeric or uninitialized. The all category represents all categories.

It does not change the semantics of every warn to die. You can do this yourself, e.g. with overriding a local $SIG{__WARN__}, or creating a warn function that does croak @_. You can even override CORE::GLOBAL::warn to change all warns, even if they are in other modules.

The CGI::Carp module has a warningsToBrowser option; you may want to look at the source code to see how it's implemented.

OTHER TIPS

It doesn't seem to work because your test isn't testing what you want to test. Try this:

use warnings FATAL => 'all';

print undef;
die 'death';

Just as a no warnings will not prevent warn from working, warnings FATAL will not make warn die.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top