Subject: | Example code in synopsis is broken |
The example code in the synopsis is broken, because the sample catch
block will always die.
# catch
if ( $e = Exception::Class->caught('MyException') ) {
warn $e->error, "\n", $e->trace->as_string, "\n";
warn join ' ', $e->euid, $e->egid, $e->uid, $e->gid, $e->pid, $e-
Show quoted text
>time;
exit;
}
elsif ( $e = Exception::Class->caught('ExceptionWithFields') ) {
$e->quixotic ? do_something_wacky() : do_something_sane();
}
else {
$e = Exception::Class->caught();
ref $e ? $e->rethrow : die $e; # <<<< HERE
}
If the eval doesn't die, $@ is ''. In the else block, this isn't checked
for - the die statement will run if $e isn't a reference.
It's a bit confusing if you're trying to get a sense for how the module
works by using the synopsis as a test :)
I ended up doing this in my code:
my $e = Exception::Class->caught();
ref $e ? $e->rethrow : $e ? die $e : undef;
I'm sure there's a nicer way.
Cheers,
Nigel