in reply to Throw customized exception without throwing

use strict; use warnings; my %exceptions = (cust1 => \&cust1Handler, cust2 => \&cust2Handler); eval { die "cust1\n"; }; if ($@) { chomp $@; die "Unhandled exception: $@\n" unless exists $exceptions{$@}; $exceptions{$@}->(); } else { print "Success\n"; } sub cust1Handler { print "Turned to custard - 1\n"; } sub cust2Handler { print "Turned to custard - 2\n"; }

Prints:

Turned to custard - 1

may be what you are after. Note the newline magic to suppress the context text that die would otherwise add.


Perl is environmentally friendly - it saves trees