On Tuesday 15 Dec 2009 14:25:28 Xiao Lan (小兰) wrote:
> On Tue, Dec 15, 2009 at 7:50 PM, Xiao Lan (小兰) <practicalp...@gmail.com> 
wrote:
> > I did have tried that, but this will get a runtime error.
> 
> Sorry this is exactly a compile-time error.
> 
> # cat except.pl
> 
> eval { $x=12/0 };
> print "0 div error" if $@;
> 
> # perl -c except.pl
> Illegal division by zero at except.pl line 2.
> 
> So, can't we capture it at runtime when meeting such error?
> 

No, you cannot capture compile-time errors at runtime. You'll need to make 
sure your code compiles before you run it. Note that you can capture such 
errors if you do perldoc -f require, perldoc -f do (for a filename), string 
eval "", etc. at run-time, in which case perl 5 invokes its compiler to 
compile some code at run-time.

But for run-time exceptions block eval { ... } should work just as well.

Regards,

        Shlomi Fish

-- 
-----------------------------------------------------------------
Shlomi Fish       http://www.shlomifish.org/
"Star Trek: We, the Living Dead" - http://shlom.in/st-wtld

Bzr is slower than Subversion in combination with Sourceforge. 
( By: http://dazjorz.com/ )

--
To unsubscribe, e-mail: beginners-unsubscr...@perl.org
For additional commands, e-mail: beginners-h...@perl.org
http://learn.perl.org/


Reply via email to