#!/usr/bin/perl use warnings; use strict; BEGIN { # control eval's bypass of die $SIG{__DIE__} = \&Splacker; } my $error_log = ''; 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 Found. eval { my $o2 = 'My::Obj'->new; die "Exception 0!"; }; # And Caught if (Splacker()) { warn 'Caught with Splacker: '.Splacker(); } # Give back die control if you want... $SIG{__DIE__} = \&CORE::die; # Exception overlooked. eval { my $o2 = 'My::Obj'->new; die "Exception 1!"; }; if ($@) { warn "Caught with \$\@: $@"; } # Exception details lost. eval { my $o2 = 'My::Obj'->new; die "Exception 2!"; 1 } or do { warn "Caught with or: $@"; }; # Same as above. use Try::Tiny; try { my $o3 = 'My::Obj'->new; die "Exception 3!"; } catch { warn "Caught with Try::Tiny: $_"; }; sub Splacker { my $error = shift || ''; if ($error eq 'DIE') { print STDERR $error.' '.$error_log; CORE::exit(1); } elsif ($error) { $error_log = $error; # print STDERR $error; } else { return $error_log; } }