The pattern I am using in the WARC test suite is to set a lexical before entering the eval and to change its value after the code that is expected to throw an exception, like so:

{ my $fail = 0; eval {new WARC::Fields (WARC_Type => 'warcinfo', BOGUS => undef); $fail = 1;}; ok($fail == 0 && $@ =~ m/key without value/, 'reject construction with missing value'); $fail = 0; eval {new WARC::Fields (WARC_Type => 'warcinfo', '::Bogus' => 1); $fail = 1;}; ok($fail == 0 && $@ =~ m/invalid field name/, 'reject construction with field name with actual leading colon' +); # more tests elided... }

This depends on what you are trying to verify; in the code above, the expected result is "execution does not continue past the bad call", but the same approach can be used to ensure that execution reaches the end of an eval block.

Back on topic, 'Zombie error' is an example of defensive programming: if the error handling do is reached, the eval must not have reached the end, because the last expression is a true constant, so there should be an error in $@. If $@ is empty, at least two things are wrong: the eval did not complete, and no reasonable error was produced.


In reply to Re: eval: Why use the 'Zombie error' idiom? by jcb
in thread eval: Why use the 'Zombie error' idiom? by DouglasDD

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.