use constant UNDEFINED_SUBROUTINE_ERROR => do { eval { no strict 'refs'; ## no critic NoStrict &{'---'}; }; my $e = $@; # Undefined subroutine &main::--- called at .../Primitives.pm line 12. my ($msg) = $e =~ / \A (.+) # 'Undefined subroutine' (?<=\s) # ' ' \S* # &main:: ---/mx or die q[Perl's error message changed! Damn! Fix this regex.]; $msg; }; sub ... { ... # If the error is that I couldn't call the # function because it didn't exist or AUTOLOAD wouldn't DWIM then # I want to return fail. # # I want to avoid Class::Delegation's misfeature of eating all # non-related errors while it traps for the few things that it # needs. if ( my $e = $@ ) { # Extreme caution here. if ( $e =~ UNDEFINED_SUBROUTINE_ERROR ) { return FAIL; } elsif ( defined blessed $e ) { # Rethrow exception objects... die $e; } else { # Rethrow exception strings... if ( not $e = /\n\z/ ) { $e .= "\n"; } die $e; } } ... }