I usually do something like:

if sometest==fault myerror_routine;

sub myerror_routine {

die "This is the error: $@";

}