A discussion in another question got me wondering: what do other programming languages\' exception systems have that Perl\'s lacks?
Perl\'s built-in exceptions are a
With Perl, language and user-written exceptions are combined: both set $@
. In other languages language exceptions are separate from user-written exceptions and create a completely separate flow.
You can catch the base of user written exceptions.
If there is My::Exception::one
and My::Exception::two
if ($@ and $@->isa('My::Exception'))
will catch both.
Remember to catch any non-user exceptions with an else
.
elsif ($@)
{
print "Other Error $@\n";
exit;
}
It's also nice to wrap the exception in a sub call the sub to throw it.