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