Hello,
In all my modules I use $SIG{__WARN__} to log warnings in a logfile. This ensures warnings are never overlooked. However, it seems some warnings cannot be caught:
package Test;
use strict;
use warnings;
sub new {
my $this = shift;
my $class = ref($this) || $this;
my $self = {};
bless($self, $class);
$SIG{'__WARN__'} = sub { print 'WARNING: '.$_[0]; };
return $self;
}
sub A {
my $self = shift;
warn 'This will trigger $SIG{__WARN__}';
}
sub B {
my $self = shift;
$self->NonExistingFunction();
}
my $test = Test->new();
$test->A();
$test->B();
The output is:
WARNING: This will trigger $SIG{__WARN__} at test.pl line 20.
Can't locate object method "NonExistingFunction" via package "Test" at
+ test.pl line 26.
So the fatal error triggered when calling a non-existing method is not caught.
How can I accomplish this?
Best regards,
Marcel
Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
Read Where should I post X? if you're not absolutely sure you're posting in the right place.
Please read these before you post! —
Posts may use any of the Perl Monks Approved HTML tags:
- a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
| |
For: |
|
Use: |
| & | | & |
| < | | < |
| > | | > |
| [ | | [ |
| ] | | ] |
Link using PerlMonks shortcuts! What shortcuts can I use for linking?
See Writeup Formatting Tips and other pages linked from there for more info.