From: "Richard J. Barbalace" <[EMAIL PROTECTED]> > Maybe I wasn't clear so people took the "die" command too literally. > There might not be a "die" command in the code at all. It might be a > subroutine that calls "die", or some statement that causes a runtime > exception, or any other means of raising a normally-fatal exception: > eval { > # Code where an error may occur > exception_causing_method(); > # Code where I want to resume after handling the exception > print "Continuing....\n"; > }; > > I want to handle the exception and then resume execution at the > following line, regardless of how the exception is caused. Can anyone > recommend a technique to do this type of resumptive exception handling > in perl?
Well ... what about just ... making the eval{} block smaller? eval { # Code where an error may occur exception_causing_method(); }; if ($@) { ... } # Code where I want to resume after handling the exception print "Continuing....\n"; You can nest the eval blocks if you need to. And you may call a subroutine to handle the exception if you'd have to enter the same code several times. Another thing ... what EXACTLY do you mean by "resume with next statement". Say your eval{} block called function Foo(), which called Bar(). And somewhere in the middle of Bar() occured an exception.Do you want to continue with Bar(). Go back into Foo() just below he call to Bar()? Go to the line of the eval{} block below the call to Foo() ? I guess the last one, but ... Anyway to tell the truth you could do this : eval { print "Ahoj\n"; $y = 0; $x = 1/$y; LEJBL: print "Cau\n"; }; if ($@) { print "ERROR: $@\n"; goto LEJBL; } If you have several places to which you'd want to return to and the error message itself yould not allow you to select use something like this: my $return_adr=0; eval { print "Ahoj\n"; $y = 0; $x = 1/$y; LEJBL0: $return_adr=1; print "Cau\n"; $y = 0; $x = 1/$y; LEJBL1: print "Jendo\n"; }; if ($@) { print "ERROR: $@\n"; goto "LEJBL$return_adr"; } But ... I would not do it. Jenda P.S.: You come from VB? "On Error Resume Next", "On Error Goto errHandler" and "Resume Next" ... I've never got used to that crazy way of doing things. =========== [EMAIL PROTECTED] == http://Jenda.Krynicky.cz ========== There is a reason for living. There must be. I've seen it somewhere. It's just that in the mess on my table ... and in my brain. I can't find it. --- me -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]