Beefy Boxes and Bandwidth Generously Provided by pair Networks
Pathologically Eclectic Rubbish Lister
 
PerlMonks  

comment on

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

There are many different opinions on this.   In Python circles, for example, there’s a truism that “it’s easier to ask forgiveness than permission,” so a widely accepted practice is to “just do it,” relying upon an exception (of a particular class) being thrown if it turns out that you can’t.   Exceptions are thrown in all sorts of benign circumstances, including “to end an iterator-loop.”   Ordinarily, code which uses the try..except..finally constructs check for a particular exception-class or classes, intercepting only those that are expected.   (As expected, exceptions which are never caught by anyone typically kill the program.)

And it turns out that Perl can do this, too.   The die() function can accept any object, not just a string, and there are several “exception class hierarchy” packages available to exploit this capability.

As it happens, I find myself using “classed exceptions” frequently, throwing exceptions in basically all of the situations where I might previously have used “a non-zero return code,” but also for benign purposes.   It’s much too late to change the name of Perl’s die() function, as if we ever would want to, but it is a bit misleading.   You are raising, or “throwing,” an exception ... which may or may not be “a bad thing.”


In reply to Re: Best practices for handling errors by sundialsvc4
in thread Best practices for handling errors by v_melnik

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: (4)
As of 2024-03-29 07:43 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found