Beefy Boxes and Bandwidth Generously Provided by pair Networks
We don't bite newbies here... much
 
PerlMonks  

Comment on

( #3333=superdoc: print w/ replies, xml ) Need Help??
sub find { my ($self, $search_item) = @_; eval { # skip expensive search if item not stored anywhere throw Signal::Search::Not_Stored unless $search_item->stored; # otherwise do expensive search $self->first; while (my $item = $self->next) { throw Signal::Search::Found if $item == $search_item; }; throw Signal::Search::Not_Found; }; if ($@) { my $e = $@; # Do NOT handle Signals here. Those propagate back # up to the caller who will handle them appropriately. throw $e if $e->isa('Signal::Search'); ... handle exceptions here ... }; };
I would argue that you have three possible return codes - NOT_STORED, FOUND, NOT_FOUND, plus all the possible exceptions that can occur. Instead of trying to shoehorn your return codes into a C-like morass of constants and bit-vectors, use signalling exceptions! Heck, you can even include a reference to the found item in your Signal::Search::Found object, if you were so inclined. And, your code is self-commenting because you make a distinction between NOT_STORED and NOT_FOUND, in case the caller or reader cares. If they don't, they can explicitly treat the two cases the same, increasing the commenting.

------
We are the carpenters and bricklayers of the Information Age.

Don't go borrowing trouble. For programmers, this means Worry only about what you need to implement.

Please remember that I'm crufty and crochety. All opinions are purely mine and all code is untested, unless otherwise specified.


In reply to Re9: Learning how to use the Error module by example by dragonchild
in thread Learning how to use the Error module by example by cleverett

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 having an uproarious good time at the Monastery: (7)
    As of 2014-08-29 21:49 GMT
    Sections?
    Information?
    Find Nodes?
    Leftovers?
      Voting Booth?

      The best computer themed movie is:











      Results (289 votes), past polls