A good set of examples of why this

eval {
   ...
};
if ($@) {
   ...
}

can be dangerous/unhelpful.

I’d say that it’s up to the caller to capture the value of $@ before doing anything else (that might obliterate it), which wipes out most of the examples, but the DESTROY example is a useful one to keep in mind. I have switched over to using the safer:

eval {
    ...
    1;
}
or do {
    die qq{Failed to do what was needed\n}. ($@ || '');
};
Advertisements