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
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |