in reply to Re: Perl try { } catch(e) { }
in thread Perl try { } catch(e) { }
catch { ... } is invoked before the block in the try { ...}, and all it does is to return the block as a reference to the anonymous function defined by the catch block.#!/usr/bin/env perl sub try(&$) { my ($try, $catch) = @_; eval { # perl try &$try }; if($@){ # perl catch &$catch($@); } } sub catch(&){ shift } try{ die("Frankie"); } catch { my $e = shift; print("Hello world $e\n"); }
|
---|
Replies are listed 'Best First'. | |
---|---|
Re^3: Perl try { } catch(e) { }
by Anonymous Monk on Mar 03, 2015 at 15:29 UTC | |
Re^3: Perl try { } catch(e) { }
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 jdeguest (Beadle) on Jun 17, 2021 at 02:47 UTC | |
by haukex (Archbishop) on Jun 17, 2021 at 08:57 UTC | |
| |
by Haarg (Priest) on Jun 18, 2021 at 04:10 UTC | |
| |
by karlgoethebier (Abbot) on Mar 24, 2021 at 21:44 UTC |