Brian Candler
7/7/2003 9:38:00 AM
On Mon, Jul 07, 2003 at 08:24:45AM +0000, Gerard A.W. Vreeswijk wrote:
> On Mon, 7 Jul 2003 17:19:26 +0900, in comp.lang.ruby you wrote:
>
> >On Mon, Jul 07, 2003 at 05:15:45PM +0900, Gerard A.W. Vreeswijk wrote:
> >> I want to catch compile time errors with my own method.
> >..
> >> Eventually,
> >> I came up with the following, which is not as I imagined. It''s ugly.
> >
> >It''s correct though - need an ''eval'' because you must have a working
> >(syntactically-valid) program A to report the error, before attempting to
> >compile invalid program B.
> >
> >The other way is with require or load:
> >
> >begin
> > require ''somefile.rb''
> >rescue Exception => e
> > puts "Error here (#{e}). May be any error, including SyntaxError"
> >end
> >
> >Regards,
> >
> >Brian.
>
>
> Thanks Brian. Still, I would not be surprised if there is a solution
> by means of opening Excpetion class.
No, there cannot be such a solution.
Ruby runs programs by
(1) parsing the code, and converting to an Annotated Syntax Tree
(2) running the AST
If step 1 fails, no code will run at all.
Brian.