jffry has asked for the wisdom of the Perl Monks concerning the following question:
I'm using Exception::Class to define my exceptions classes, but I just stumbled into a design question. Should create lots of exception subclasses like this?
But if the subclasses SomeSpecificError, AnotherProblem, DontDoThat aren't different, then why have them? I was thinking of replacing those subclasses with fields under SomeThingy. Like this:MyExceptions::SomeThingy MyExceptions::SomeThingy::SomeSpecificError MyExceptions::SomeThingy::AnotherProblem MyExceptions::SomeThingy::DontDoThat
And then I throw them:MyException::SomeThingy' => { isa => 'MyException', description => 'Bad things happen here.', fields => [ 'descriptor', 'value' ], };
Hmmm. So I guess my question is, if all those subclasses do the same thing, am I getting anything out of creating them all? Other than the name of the exception itself tells me something about the error? If that is all I am gaining, then doesn't using fields make more sense? I'm new to OO, and new to using Perl as anything other than a glorified awk. Thanks.MyException::SomeThingy->throw( 'error' => 'You did something I didnt like.', 'descriptor' => 'DontDoThat', 'value' => $bad_variable, );
UPDATE: This page covers what I was asking, too, in the paragraph titled "Write Sensible Throws Clauses".
|
---|
Replies are listed 'Best First'. | |
---|---|
Re: Exception Classes Advice on Subclasses
by adrianh (Chancellor) on Dec 21, 2005 at 10:16 UTC | |
Re: Exception Classes Advice on Subclasses
by tirwhan (Abbot) on Dec 21, 2005 at 10:28 UTC | |
Re: Exception Classes Advice on Subclasses
by venk (Acolyte) on Dec 21, 2005 at 13:39 UTC | |
Re: Exception Classes Advice on Subclasses
by halley (Prior) on Dec 21, 2005 at 17:25 UTC | |
by BrowserUk (Patriarch) on Dec 21, 2005 at 18:22 UTC | |
Re: Exception Classes Advice on Subclasses
by blazar (Canon) on Dec 21, 2005 at 11:13 UTC | |
Re: Exception Classes Advice on Subclasses
by perrin (Chancellor) on Dec 21, 2005 at 17:38 UTC | |
Re: Exception Classes Advice on Subclasses
by jesuashok (Curate) on Dec 21, 2005 at 05:29 UTC | |
by jffry (Hermit) on Dec 22, 2005 at 00:31 UTC |
Back to
Seekers of Perl Wisdom