Beefy Boxes and Bandwidth Generously Provided by pair Networks
Think about Loose Coupling
 
PerlMonks  

comment on

( [id://3333]=superdoc: print w/replies, xml ) Need Help??
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


In reply to Nice style for interesting error messages by dash2

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post; it's "PerlMonks-approved HTML":



  • Are you posting in the right place? Check out Where do I post X? to know for sure.
  • Posts may use any of the Perl Monks Approved HTML tags. Currently these include the following:
    <code> <a> <b> <big> <blockquote> <br /> <dd> <dl> <dt> <em> <font> <h1> <h2> <h3> <h4> <h5> <h6> <hr /> <i> <li> <nbsp> <ol> <p> <small> <strike> <strong> <sub> <sup> <table> <td> <th> <tr> <tt> <u> <ul>
  • Snippets of code should be wrapped in <code> tags not <pre> tags. In fact, <pre> tags should generally be avoided. If they must be used, extreme care should be taken to ensure that their contents do not have long lines (<70 chars), in order to prevent horizontal scrolling (and possible janitor intervention).
  • Want more info? How to link or How to display code and escape characters are good places to start.
Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others drinking their drinks and smoking their pipes about the Monastery: (6)
As of 2024-04-24 10:59 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found