Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl-Sensitive Sunglasses

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 jffry

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!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • 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
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            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?

    What's my password?
    Create A New User
    and all is quiet...

    How do I use this? | Other CB clients
    Other Users?
    Others drinking their drinks and smoking their pipes about the Monastery: (7)
    As of 2018-05-24 12:35 GMT
    Find Nodes?
      Voting Booth?