Why doesn't use warnings FATAL => 'all' seem to work?
Asked Answered
L

2

6

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.

Lyonnesse answered 11/6, 2013 at 14:56 Comment(0)
T
9

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.

Thadeus answered 11/6, 2013 at 15:7 Comment(0)
H
11

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.

Haugen answered 11/6, 2013 at 15:8 Comment(0)
T
9

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.

Thadeus answered 11/6, 2013 at 15:7 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.