#=================================== sub uncaught_error { #=================================== die @_ if ref $_[0] # already an exception object || ! defined $^S; # code is being compiled my ($class) = caller(0); # throw() does the work of inflating @_ = ( $class, 'Uncaught', join( '', @_ ) ); # an error message into an exception object goto $class->can('throw') || \&throw; # of the relevant class } $SIG{__DIE__} = \&uncaught_error;