in reply to Re^2: conditional catch-blocks 'try {} catch(COND) { }'
in thread conditional catch-blocks 'try {} catch(COND) { }'
maybe?#!/usr/bin/perl use warnings; use strict; use Try::Tiny; sub handle_error { my ($e, $dispatch_error) = @_; my $error_type = ref $e; $error_type = '' unless exists $dispatch_error->{$error_type}; $dispatch_error->{$error_type}->($e); return } for my $case (0, 1, 2) { try { [ sub { die bless {source => 'Int', target => 'Float'}, 'TypeE +rror' }, sub { die bless {value => 2**65, min => -2**32, max => 2**32}, 'RangeError' }, sub { die bless {}, 'Segmentation Fault' } ]->[$case]->() } catch { handle_error($_, { TypeError => sub { warn "Coercing type $_[0]{source} to $_[0]{target}" }, RangeError => sub { warn "$_[0]{value} not between $_[0]{min} and $_[0]{ma +x}" }, '' => sub { die $_[0] }, }); }; print "next\n"; }
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^4: conditional catch-blocks 'try {} catch(COND) { }'
by afoken (Chancellor) on Sep 21, 2021 at 11:29 UTC | |
by LanX (Saint) on Sep 21, 2021 at 11:39 UTC | |
by afoken (Chancellor) on Sep 21, 2021 at 18:54 UTC | |
by LanX (Saint) on Sep 21, 2021 at 21:33 UTC | |
|
Re^4: conditional catch-blocks 'try {} catch(COND) { }'
by LanX (Saint) on Sep 21, 2021 at 13:16 UTC |