Superfox il Volpone has asked for the wisdom of the Perl Monks concerning the following question:
I know this snippet from Programming Perl 4th ed,pp 329, and it works using locals:try { die ("Hello world"); } catch(e) { print("Exception: " $e); }
And this works as try { ... } catch { print("Exception caught: $_"); };sub try(&$) { my ($try, $catch) = @_; eval { # perl try &$try }; if($@){ # perl catch local $_ = $@; &$catch(); } } sub catch(&){ $_[0]; }
|
---|
Replies are listed 'Best First'. | |
---|---|
Re: Perl try { } catch(e) { }
by Corion (Patriarch) on Mar 03, 2015 at 14:27 UTC | |
by Superfox il Volpone (Sexton) on Mar 03, 2015 at 15:18 UTC | |
by Anonymous Monk on Mar 03, 2015 at 15:29 UTC | |
by karlgoethebier (Abbot) on Mar 03, 2015 at 17:39 UTC | |
by jdeguest (Beadle) on Mar 24, 2021 at 03:29 UTC | |
by haukex (Archbishop) on Mar 24, 2021 at 08:51 UTC | |
| |
by karlgoethebier (Abbot) on Mar 24, 2021 at 21:44 UTC | |
Re: Perl try { } catch(e) { }
by Anonymous Monk on Mar 03, 2015 at 17:13 UTC |