Beefy Boxes and Bandwidth Generously Provided by pair Networks
Just another Perl shrine
 
PerlMonks  

comment on

( [id://3333]=superdoc: print w/replies, xml ) Need Help??
Obviously, it depends...

The first thing to say is that, if you are using sub is known at compile time (e.g. its not an object-method), then you should probably use prototypes: then you get the errors, not your users:

sub foo ($$) { print "@_\n"; } foo(1,2,3); % perl foo.pl Too many arguments for main::foo at foo.pl line 2, near "3)" Execution of foo.pl aborted due to compilation errors.
If you want to do run-time checking, then you should consider that it may well be end-users who see the errors, not the person writing the script. In this case, I'd use the following guidelines:
  • If possible, have default values for params not supplied -- then its not an error
  • If you really want to die, then you should provide an error message that tells the user that its not their fault:

    Internal Error: The script you are running has found an error made by its programmer, and regrets that it is unable to continue. Please email (the developer), and include the following information (... stack dump ...). Please accept our appologies

Basically, detailed messages probably won't help the user, so don't confuse them. --Dave.

In reply to Re: What Are The Rules For Subs And Modules When Fed Wrong Input by dpuu
in thread What Are The Rules For Subs And Modules When Fed Wrong Input by Cody Pendant

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 about the Monastery: (7)
As of 2024-03-28 11:14 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found