Beefy Boxes and Bandwidth Generously Provided by pair Networks
laziness, impatience, and hubris
 
PerlMonks  

Re: (Guildenstern) Re: "Obviously, You Will Need a Java Course..."

by McD (Chaplain)
on Apr 04, 2001 at 20:20 UTC ( [id://69719]=note: print w/replies, xml ) Need Help??


in reply to (Guildenstern) Re: "Obviously, You Will Need a Java Course..."
in thread "Obviously, You Will Need a Java Course..."

Guildenstern writes:

I'm not sure if Perl supports error handling in the same manner (try and catch, or similar), but I'm sure somebody here can clue me in.

darobin mentions this below - use eval BLOCK with die to catch and throw exceptions:

eval { # code that might die }; if ($@) { # $@ contains your exception }
Peace,
-McD

Update: merlyn is right, of course - forgot the ";". Curse my flying fingers! :-)

  • Comment on Re: (Guildenstern) Re: "Obviously, You Will Need a Java Course..."
  • Download Code

Replies are listed 'Best First'.
Re: Re: (Guildenstern) Re: "Obviously, You Will Need a Java Course..."
by merlyn (Sage) on Apr 04, 2001 at 20:38 UTC
    eval { # code that might die } if ($@) { # $@ contains your exception }
    Don't forget the semicolon after the eval {}. That kind of eval is an expression, not a statement, so it needs a semicolon to become a statement.

    -- Randal L. Schwartz, Perl hacker

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://69719]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others chanting in the Monastery: (4)
As of 2024-04-20 08:15 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found