Beefy Boxes and Bandwidth Generously Provided by pair Networks RobOMonk
Clear questions and runnable code
get the best and fastest answer
 
PerlMonks  

Comment on

( #3333=superdoc: print w/ replies, xml ) Need Help??
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?
MyExceptions::SomeThingy MyExceptions::SomeThingy::SomeSpecificError MyExceptions::SomeThingy::AnotherProblem MyExceptions::SomeThingy::DontDoThat
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:
MyException::SomeThingy' => { isa => 'MyException', description => 'Bad things happen here.', fields => [ 'descriptor', 'value' ], };
And then I throw them:
MyException::SomeThingy->throw( 'error' => 'You did something I didnt like.', 'descriptor' => 'DontDoThat', 'value' => $bad_variable, );
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.

UPDATE: This page covers what I was asking, too, in the paragraph titled "Write Sensible Throws Clauses".


In reply to Exception Classes Advice on Subclasses by je44ery

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post; it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • Outside of code tags, you may need to use entities for some characters:
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.
  • Log In?
    Username:
    Password:

    What's my password?
    Create A New User
    Chatterbox?
    and the web crawler heard nothing...

    How do I use this? | Other CB clients
    Other Users?
    Others cooling their heels in the Monastery: (10)
    As of 2014-04-18 18:49 GMT
    Sections?
    Information?
    Find Nodes?
    Leftovers?
      Voting Booth?

      April first is:







      Results (471 votes), past polls