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??
In an experiment that involved abusing Perl quite badly, I discovered the "try/catch" method explored1 in The Camel Book, which implements a pseudo-C++ style of error checking and recovery. The usage is paraphrased here:
try { die "screaming"; } catch { /screaming/ and print "Stop screaming.\n"; };
This is implemented using the ability of Perl to have anonymous subs passed as parameters to functions, provided they have a compatible prototype2 such as sub try(&$){}.

Implementation details aside, has anyone used this try/catch method in Perl to any significant degree, or is there an alternative methodology that is more dependable? Just curious. Exceptions (i.e. die) in C++ are quite interesting. I am thinking that this might be used, for example, to more reliably trap DBI errors in Web applications.

Or, of course, I might be completely delusional.
1. "Programming Perl", Chapter 2 - Prototypes
2. For some reason, you can only have the function as the first operator in your prototype, which works fine for map, grep, and what have you, but is strangely rigid considering the broader scope of Perl.

In reply to Error Checking: Have you tried 'Try/Catch'? by tadman

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 lurking in the Monastery: (5)
As of 2024-04-25 19:59 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found