EDIT
The problem was solved

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

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.