Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl-Sensitive Sunglasses

Re: Intelligent Exception Handling in Perl

by Abigail-II (Bishop)
on Jul 22, 2003 at 20:25 UTC ( #276911=note: print w/replies, xml ) Need Help??

in reply to Intelligent Exception Handling in Perl

In the fast majority of the code I write, I use plain old die, without wrapping them in eval. But this has more to do with the kind of programs I write than with a deeper philosophy. Most programs I write run quickly and are of the form "here's a bunch of things (files, arguments, environment variables, URLs), produce something". And the something can either be produced, or it can't. So, if there's something missing, or wrong, about the 'bunch of things', nothing should be produced, and the program should terminate with an error message. Which is exactly what die does.

Programs performing database modifications do use another technique though. There I will do things like:

eval { start transaction or die; ... prepare or die; ... execute or die; ... fetch or die; ... }; if ($@) { rollback; die $@; } else { commit; }

If something goes, I die as usual, but this die will be caught, the transaction will be rolled back, and we cascade the die upwards (where it's most likely not caught again).


Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://276911]
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others meditating upon the Monastery: (7)
As of 2021-04-19 15:08 GMT
Find Nodes?
    Voting Booth?

    No recent polls found