Are you trying to catch errors loading the module? If so, that won't work. use Module occurs at compile-time. Change it to require Module;. But trying to resume is probably not going to work since you have a half-loaded module. On the plus side, the error you gave is unlikely to occur from loading a module.

Otherwise, yes, it will catch exceptions thrown by SomeSub and subs called by SomeSub (and subs called by subs called by ...).

Exceptions unwind out of every sub until an eval catches it or until Perl itself is exited.

sub SomeOtherSub { print "c\n"; undef->foo(); print "d\n"; } sub SomeSub { print "b\n"; SomeOtherSub(); print "e\n"; } print "a\n"; eval { SomeSub(); 1 } or print("Caught an error!\n"); print "f\n";
a b c Caught an error! f

Honestly, you've been very vague in describing the problem you want to solve. It's very hard to help you.

Why eval call uses {}?

Arguments are normally evaluated before the function to which they are passed. In eval's case, the argument is a block of code which will be evaluated by eval itself. do, map and grep are other functions that takes a code block for argument. They are similar to for and while, but these two can't be used in expressions.


In reply to Re^3: Handling errors occuring inside complex modules by ikegami
in thread Handling errors occuring inside complex modules by vit

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.