http://qs1969.pair.com?node_id=54046

dash2 has asked for the wisdom of the Perl Monks concerning the following question:

I'm writing a module to do WHOIS lookups on domain names. The actual WHOIS lookup is relatively unusual for the following reason. Normally, interesting values are returned on the success of some method. Failure is uninteresting. So we use 0 or undef for failure. In a WHOIS, success is uninteresting: if a domain name is available, it's available. Failure, OTOH, is interesting: is the domain already bought? Or the whois server didn't respond? Or you couldn't contact the server? Or some internal script error?

So my question is, what is a nice way to handle "interesting" errors? I can think of a few:

1) Have failure return true (with an error message) and success false. Elegant, but counter-intuitive.

2) Have the subroutine/method return two values: success/failure, and an optional error message. Straightforward, but that extra value is going to waste space most of the time, and it's a bore to write your method calls always to expect two values.

3) Return true/false as normal for success/failure, and write to an object variable for the error message: e.g.
$success = $domain->do_whois() or print "Failed:". $domain->{whois_error}; I guess this is what the DBI module does. Perhaps this is best?

Opinions would be interesting. TMTOWDI and all that, of course, but I'd like to hear some views on the right way in particular situations.

Dave