Does this qualify as a simplified version of the code snippet below? eval{ print "begin\n"; die "throw"; print "done main\n"; }; if(my $err=$@){ print "Exception = $err\n"; } else { print "No exception\n"; }
When I single step thru this with the Open Perl IDE debugger on ActiveState Perl 5.8+, it prints "No Exception". I'm expecting it to print "Exception = throw". Is there a bug in my program, a bug in perl, or a bug in me? Thanks! Siegfried -----Original Message----- From: Randy W. Sims [mailto:[EMAIL PROTECTED] Sent: Monday, January 03, 2005 1:03 AM To: Siegfried Heintze Cc: beginners@perl.org Subject: Re: $@ not working Siegfried Heintze wrote: > I have the following code (extracted from my cgi program) and I am expecting > it to display an error message when it hits the "if ($@){...}" as a result > of hitting the "die" statement. It does not (as indicated by single stepping > with the windows perl debugger)! Instead it takes the else! Why? Did you try the code snippet below as posted? It runs as expected here. > I'm using ActiveSTate 5.8+. I tried perldoc.bat -f die but did not find any > clues to my problem. > > eval{ > > die "No valid ID for User"; > }; > if($@){ However, you probably want to save the error: if ( my $err = $@ ) { > print start_html(-title => "Error: $case_name", > -onload => "BodyLoad();", > -style => {"src"=>"../../css/convex.css"} > ), > p("<h1> Error: $@"); And change this to: p("<h1> Error: $err"); because $@ has been reset by the time you get here. > print concat( [EMAIL PROTECTED]); > } else { > > } > > Thanks, > Siegfried > > Randy. -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] <http://learn.perl.org/> <http://learn.perl.org/first-response> -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] <http://learn.perl.org/> <http://learn.perl.org/first-response>