1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
#!/usr/bin/perl
use warnings;
event_start();
print "Should be visible even there is a warning";
sub event_start {
OUTER: {
$SIG{__WARN__} = sub {
print STDOUT "\nWarning generated:\n", @_, "\n";
last OUTER; #should break out the OUTER /event_start function
};
print "Start\n";
if("test"==1){ print "create warning"; }
print "Should not be shown";
}
}
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28
#!/usr/bin/perl use strict; use warnings; print "Start\n"; event_start(); print "Should be visible even there is a warning\n"; sub event_start { my $ret=0; my $val='test'; my $ok=eval { local $SIG{__WARN__} = sub { die( "\nWarning generated:\n", @_ ); }; $ret++ if($test==1) ; return 1; }; unless($ok) { my $func_name=(caller(0))[3]; print "format error in $func_name ($@)\n"; return 0; } return $ret; }
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18
sub foo { local $SIG{__WARN__} = sub { say "warning passiert, breche ab. @_"; die '__INTERNAL_WARNING__'; }; warn 'Das ist ein Test'; say 'Ein Text, der nie kommt'; } eval { foo(); }; if ($@ and $@ !~ /^__INTERNAL_WARNING__/) { die $@; } warn 'Warning ausserhalb'; say 'Ganz zum Schluss';
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
#!/usr/bin/perl
use warnings;
eval { event_start(); };
print "Should be visible even there is a warning";
sub event_start {
local $SIG{__WARN__} = sub {
print STDOUT "\nWarning generated:\n", @_, "\n";
die;
};
print "Start\n";
if("test"==1){ print "create warning"; }
print "Should not be shown";
}