Beefy Boxes and Bandwidth Generously Provided by pair Networks
No such thing as a small change

Comment on

( #3333=superdoc: print w/replies, xml ) Need Help??

Interesting thread. Thanks for launching it.

I wrestled with this recently and, while I know a lot of monks more experienced than me would recommend just die-ing on error, I decided to use a softer approach. I created a few error-handling methods for my class that can be called as follows:

$obj->set_err( 'Something went boom' ); my $msg = $obj->err_str; my $trace = $obj->err_trace; # error msg + full stack trace

The main reasons I went with this approach are:

  1. I didn't want to wrap nearly every method call with an eval
  2. I consider very few of the possible errors to be fatal-worthy
  3. I wanted the methods to have the ability to pass information back to the caller as a warning even if the method succeeds (e.g., over-writing data may or may not be intentional)
In short, I wanted my class to be able to warn (or carp) that something might be fishy (e.g., with the input data) without die-ing all the time, and I didn't want the behavior of the class to overly-influence how I wrote the calling program. (I work in research and it is common to write a one-off to explore an idea; in some cases this means using data that may cause the class methods to throw errors that I want to ignore, and continue processing without having to work around fatal exceptions.)

I realize this may be a choice that goes against accepted conventions, and over time (as my modules mature and become more battle-tested) I may change the way errors are handled. For now, though, this approach works well.

In reply to Re: How do I report an error back to the user of my object? by bobf
in thread How do I report an error back to the user of my object? by SomeNetworkGuy

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 lurking in the Monastery: (6)
    As of 2018-06-21 23:06 GMT
    Find Nodes?
      Voting Booth?
      Should cpanminus be part of the standard Perl release?

      Results (120 votes). Check out past polls.