I like this as well, but I usually go one step futher.
I leave it up to the user how to handle the error, so that they can write code according to how they want to.. I usually allow a definition via the new() method or say $obj->set(err_handler, 1)
I usually roll my own error methods, and then if an error occurs I call the error method. Based on how the called function was called (the one that caputered the error), and the preferences defined in the object, I will return the error, return 2 elems first being undef and second the actual error, return undef and set error or errstr, or actually handle the via die/warn or croak (if Carp has been use()'d...
Its alot of work to go through originally, but it allows the user of the package great flexibility.. The same package supports the following snippets..
$obj->method || die "$obj->{errstr}\n";
# or even
$obj->method || handle_errors; # where this is a custom sub
# OR
(@foo) = $obj->method;
die "$foo[1]\n" unless ( defined($foo[0]) );
# OR
@foo = $obj->method;
# and I catch the error and die out...
Its nice to leave the programming to the programmer, and not force them to jump through my particular flaming hoops, as I'm sure they have more than enough to jump through on thier own, or they probably wouldnt be using my module in the first place ;)
/* And the Creator, against his better judgement, wrote man.c */
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, details, 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, summary, 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: |
| & | | & |
| < | | < |
| > | | > |
| [ | | [ |
| ] | | ] |
Link using PerlMonks shortcuts! What shortcuts can I use for linking?
See Writeup Formatting Tips and other pages linked from there for more info.