Sometimes it's nice to have a single exception block guarding several potentially fatal operations. This lets you re-use error-handling code. However, sometimes you can recover from a single exception and move on to the next operation. Unfortunately, Perl doesn't really support this.
That's why I wrote some very simple code. Here's how it looks like from the Perl side:
#!/usr/bin/perl use strict; use warnings; use Runops::Resume; my $text; eval { $text = 'before'; print $text, "\n"; $text = 'after'; die "Goodbye!\n"; print $text, "\n"; }; warn "Died '$@'" if $@; resume();
As you ought to expect, the output is:
before Died 'Goodbye! ' at example.pl line 17. after
Note that declaring lexicals within the eval block doesn't quite work correctly. That would be scary code.
Between Perl and C, it's fewer than 70 lines of well-spaced code. It's reasonably trivial to make a stack of resumable exceptions, too -- probably fewer than ten more lines of C. Runops::Resume.