#!/usr/bin/perl
use warnings;
use strict;
BEGIN {
# control eval's bypass of die
$SIG{__DIE__} = \&Splacker;
}
print $], "\n";
{ package My::Obj;
sub new {
my $class = shift;
bless {@_}, $class
}
sub DESTROY {
my $self = shift;
eval { 1 } if ! $self->{finished};
}
}
my $o1 = 'My::Obj'->new(finished => 1);
undef $o1;
# Exception overlooked.
eval {
my $o2 = 'My::Obj'->new;
die "Exception!";
};
if ($@) {
warn "Caught with \$\@: $@";
}
# Exception details lost.
eval {
my $o2 = 'My::Obj'->new;
die "Exception!";
1 } or do {
warn "Caught with or: $@";
};
# Same as above.
use Try::Tiny;
try {
my $o3 = 'My::Obj'->new;
die "Exception!";
} catch {
warn "Caught with Try::Tiny: $_";
};
sub Splacker {
my $error = shift;
print $error;
CORE::exit(1);
}
####
5.008008
Exception! at C:\xampp\cgi-bin\Test\tester.pl line 32.
##
##
Caught with or: at C:\xampp\cgi-bin\Test\tester.pl line 44.
Caught with Try::Tiny: at C:\xampp\cgi-bin\Test\tester.pl line 55.
5.008008
Exception! at C:\xampp\cgi-bin\Test\tester.pl line 32.
Exception! at C:\xampp\cgi-bin\Test\tester.pl line 42.
Exception! at C:\xampp\cgi-bin\Test\tester.pl line 53.
##
##
sub Splacker {
my $error = shift;
print STDERR $error;
}
##
##
Exception! at C:\xampp\cgi-bin\Test\tester.pl line 32.
Exception! at C:\xampp\cgi-bin\Test\tester.pl line 42.
Caught with or: at C:\xampp\cgi-bin\Test\tester.pl line 44.
Exception! at C:\xampp\cgi-bin\Test\tester.pl line 53.
Caught with Try::Tiny: at C:\xampp\cgi-bin\Test\tester.pl line 55.
5.008008