In an experiment that involved abusing Perl quite badly,
I discovered the "try/catch" method explored
1 in
The Camel Book,
which implements a pseudo-C++ style of error checking and
recovery. The usage is paraphrased here:
try {
die "screaming";
} catch {
/screaming/ and print "Stop screaming.\n";
};
This is implemented using the ability of Perl to have
anonymous subs passed as parameters to functions, provided
they have a compatible prototype
2 such as
sub try(&$){}.
Implementation details aside, has anyone used this
try/catch method in Perl to any significant degree, or is
there an alternative methodology that is more dependable?
Just curious. Exceptions (i.e.
die) in C++ are quite
interesting. I am thinking that this might be used, for
example, to more reliably trap DBI errors in Web applications.
Or, of course, I might be completely delusional.
1. "Programming Perl", Chapter 2 - Prototypes
2. For some reason, you can only have the function as the
first operator in your prototype, which works fine
for
map,
grep, and what have you, but is strangely
rigid considering the broader scope of Perl.