#!/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); }