NOTE
The code below is a simple concise example of a behavior I want to achieve. It is by no means intended to describe my actual use case. Suffice to say that this particular wart of the perl language is annoying enough for me to wanting to devise a generic way of dealing with it. This site has surprised me before, no reason it can't offer something I never thought of here as well :)
The question is very very simple. How do I make this work:
perl -Mwarnings -Mstrict -E ' sub DESTROY { say "invoked destructor"; die "aieeee" } say "creating object"; { bless( {} ) } say "object destroyed (should not reach here): $@" '
In case it isn't clear - I want to make it so that the "should not reach here" line is never, well reached. In other words - have an "armed" scope guard object throw a real exception. Note: I want an exception, i.e. something trappable. Hence the exit() trick does not apply, since it will kill the entire process.
Cheers
In reply to Throw from within a DESTROY block by ribasushi
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |