In an experiment that involved abusing Perl quite badly,
I discovered the "try/catch" method explored1 in The Camel Book,
which implements a pseudo-C++ style of error checking and
recovery. The usage is paraphrased here:
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.
This is implemented using the ability of Perl to have anonymous subs passed as parameters to functions, provided they have a compatible prototype2 such as sub try(&$){}.try { die "screaming"; } catch { /screaming/ and print "Stop screaming.\n"; };
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.
|
---|
Replies are listed 'Best First'. | |
---|---|
Re: Error Checking: Have you tried 'Try/Catch'?
by mirod (Canon) on Feb 20, 2001 at 12:22 UTC | |
Re: Error Checking: Have you tried 'Try/Catch'?
by brother ab (Scribe) on Feb 20, 2001 at 16:57 UTC | |
Re: Error Checking: Have you tried 'Try/Catch'?
by BrentDax (Hermit) on Feb 20, 2001 at 14:31 UTC | |
by tadman (Prior) on Feb 20, 2001 at 15:02 UTC | |
Re: Error Checking: Have you tried 'Try/Catch'?
by PsychoSpunk (Hermit) on Feb 20, 2001 at 11:56 UTC |
Back to
Meditations