Beefy Boxes and Bandwidth Generously Provided by pair Networks
Problems? Is your data what you think it is?
 
PerlMonks  

Re: Exception Classes Advice on Subclasses

by adrianh (Chancellor)
on Dec 21, 2005 at 10:16 UTC ( #518271=note: print w/ replies, xml ) Need Help??


in reply to Exception Classes Advice on Subclasses

Hmmm. So I guess my question is, if all those subclasses do the same thing, am I getting anything out of creating them all?

You get a more convenient syntax for catching particular exceptions. For example:

if ( my $e = MyException->caught ) { ... } elsif ($@) { die $@; }

much easier than delving into fields to figure out what kind of exception has been thrown.

You also get a simple way to represent a hierarchy of exception types. If you have a general ValidationError exception class, with a DateValidation, NameValidation, etc. subclasses then you could capture all of the subclasses with a single ValidationError->caught.


Comment on Re: Exception Classes Advice on Subclasses
Select or Download Code

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others wandering the Monastery: (6)
As of 2014-10-01 22:46 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    What is your favourite meta-syntactic variable name?














    Results (40 votes), past polls