I'm personally a fan of $object->errstr, with methods returning 0 on failure. You will either agree or you won't.
Almost the same here. I use error, not errstr (try pronouncing errstr). And I return nothingness on failure.
That's a plain return;. It has the benefit of being undef in scalar context, but an empty list in list context.
Juerd
- http://juerd.nl/
- spamcollector_perlmonks@juerd.nl (do not use).
| [reply] [d/l] |
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 */ | [reply] [d/l] |
-sauoq
"My two cents aren't worth a dime.";
| [reply] |
air-stir
While I also agree that error is better, if something isn't really pronouncable I usually "expand it". In this case, errstr becomes error string when reading; just like usr (as in /usr/bin/perl) becomes user instead of us-are.
| [reply] [d/l] [select] |