Perl Moo Throwable Example
has type => (is=>‘ro’); has msg => (is=>‘ro’);
sub e { if (ref($) eq ‘Ex’) { return $; } else { chomp; return Ex->new(msg => $_, type=>0); } }
sub tu { Ex->throw({type => 1, msg => ‘dont die while root’}); }
sub ta { croak “death by disruptor”; }
my $x = X::Nix->new();
try { $x->tu; } catch { printf “died with %d and said: <%s>\n”, Ex::e->type, Ex::e->msg; };
try { $x->ta; } catch { printf “died with %d and said: <%s>\n”, Ex::e->type, Ex::e->msg; };