harryf has asked for the wisdom of the Perl Monks concerning the following question:
Hi,
Fielding for opinions. Have a code base where I essentially need Java-style exception handling (try/catch/finally etc.) - so far have used Carp (croak) and eval / if ($@) style reporting / handling but it's reached the point where I need to be able to "filter" for different categories of error and respond appropriately. Also want to avoid using some kind of convention based on the contents of the error message.
For example in calling some object method, which executes a SELECT statement, there could be some kind of fundamental (e.g. the db is down) or there might be something "wrong" with the data selected - an "application logic error". On encountering the application logic error, the process can continue but if the DB is down, the process should die.
Anyway - looking around, Error seems to be the most promising way forward (from this article). From experiments, it seems good but I'm nervous about introducing it because it's a such a fundamental change, and wondering how other people feel about it - stability / gotchas etc.
Some random thoughts / questions;
The conclusion I'm starting to draw is "yes" to throw and "use base qw(Error)" but no to try/catch etc. - rather use eval like;
eval { doSomething(); }; if ( $@ ) { if ( $@->isa('my::own::error') ) { warn("Error occurred but may continue: $@"); } else { # Catch other thrown errors, die, croak etc. die(ref $@ ? $@->stacktrace() : $@); } }
Anyway - opinions / experiences very much appreciated.
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Opinions of Error.pm
by Excalibor (Pilgrim) on Sep 04, 2006 at 13:12 UTC | |
|
Re: Opinions of Error.pm
by rvosa (Curate) on Sep 04, 2006 at 17:57 UTC | |
by astroboy (Chaplain) on Sep 10, 2006 at 03:12 UTC | |
|
Re: Opinions of Error.pm
by adrianh (Chancellor) on Sep 04, 2006 at 18:11 UTC | |
by diotalevi (Canon) on Sep 05, 2006 at 02:36 UTC | |
by harryf (Beadle) on Sep 05, 2006 at 06:57 UTC | |
by adrianh (Chancellor) on Sep 05, 2006 at 08:10 UTC | |
|
Re: Opinions of Error.pm
by ftumsh (Scribe) on Sep 05, 2006 at 16:21 UTC | |
by snowhare (Friar) on Sep 06, 2006 at 11:18 UTC | |
|
Re: Opinions of Error.pm
by Anonymous Monk on Sep 05, 2007 at 21:02 UTC |