Beefy Boxes and Bandwidth Generously Provided by pair Networks
There's more than one way to do things
 
PerlMonks  

comment on

( [id://3333]=superdoc: print w/replies, xml ) Need Help??
I think this depends on the general error handling strategy of the whole application. When developing and working out the 'nitty-gritty' in subs, modules etc. (especially with command-line-based apps), I like the code to die there and then.

Eventually though, once the errors (hopefully!) are down to being only those that are likely to be thrown by strange input/ system failures etc. (rather than buggy code), I'll fit the error handling into the 'bigger picture' - this could be "report to user and die", but it may also be "report to user, but ignore and continue", "report via email to sysadmin and ignore", "report to eveybody in 100m radius and SHUT DOWN THE POWER NOW GOD DAMMIT LETS GET THESE PEOPLE OUTTA HERE!!" etc.

Where this reporting (or not) happens is then just a matter of personal preference. Some people like to call "Report_Error($error)" everywhere, while some people like to check return values and report in a single place (as part of the 'main loop' logic say). The 'C-style' code you demonstrate is appropriate for the latter - if the sub failed, the error can be propagated up nicely and the 'main logic' can take the appropriate action - trying another sub for instance, rather than having the failing sub dictate its own strategy.

Cheers, Ben.


In reply to Re: return eval { die() } idiom by benn
in thread return eval { die() } idiom by lestrrat

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 having an uproarious good time at the Monastery: (6)
As of 2024-04-18 05:25 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found