Greetings!
I am using Error.pm at the moment on a relatively big project without much of a hussle. From this experience, using Error.pm is probably better than doing your own exception code for the following reasons:
- nice (and predictable) layout of exceptions hyerarchy (by using your own exception base class you get the whole thing, and it croaks when you try to throw an Exception you don't have)
- makes the checking easier (if you miswrite your class name on your examplo above, you'll never treat that exception right, but you cannot catch with (or throw) an unknown exception
- makes the code easily maintainable and easier on the reading than barebones eval/if($@), and this is Good(tm)
My take on exception handling was this (just in case it may be useful to you), which is surely improveable, but I'm not going to touch it now ;-)
- use Error.pm as the base class of my hyerarchy of exceptions
- use 'throw' or 'die with' to generate exceptions
- use Log::Log4perl (but surely any other logging way will work) to leave the exceptions message (so that the information about the failure is logged down, and it's the type (or class) of the Exception what's propagated to the upper levels (so the log has detailed info about the failure, usually with different info at different logging 'depths' (i.e. simpler for ERROR but more verbose for DEBUG), and simple reasons for the exceptions messages themselves...)
- following Erlang's failure system, I just catch (by using eval or the module's :try keywords) the exceptions I know how to treat and let everything else to float up to the toplevel, where appropriate actions (usually dying) are taken
briefly: extensive logging and a nice exception hyerarchy with the alternate constructors from Error.pm which make everything easier to read.
Using try/catch with/catch/otherwise has worked nicely in some parts of the project and horribly in others (hosted Perl code which mangles with the C server that manages the Perl code, making dying really bad (lost place of dying, lost of cause and the stacktrace, etc...), so YMMV...
Good luck!
--
our $Perl6 is Fantastic;