eval {
# code that could die
};
if ($@) { # Poor man's catch!
####
eval {
# code that could die;
1 } or do {
##
##
#!/usr/bin/perl
use warnings;
use strict;
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: $_";
};
##
##
5.020001
Caught with $@: Exception! at ./eval.pl line 25.
Caught with or: Exception! at ./eval.pl line 34.
Caught with Try::Tiny: Exception! at ./eval.pl line 44.
##
##
5.012005
Caught with or: at eval.pl line 36.
Caught with Try::Tiny: at eval.pl line 46.
##
##
($q=q:Sq=~/;[c](.)(.)/;chr(-||-|5+lengthSq)`"S|oS2"`map{chr |+ord
}map{substrSq`S_+|`|}3E|-|`7**2-3:)=~y+S|`+$1,++print+eval$q,q,a,