From: Robert Klemme Date: 2003-07-07T21:17:29+09:00 Subject: Re: trapping compile time errors "Gerard A.W. Vreeswijk" schrieb im Newsbeitrag news:3f093a9f.6962781@news.cs.uu.nl... > On Mon, 7 Jul 2003 17:19:26 +0900, Brian Candler > 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. > > Allright. This is good. Still, I hope it is possible to report > syntax errors other than by eval. Or am I aiming for the impossible? > (In Perl it is possible anyway.) > > Why I want it is to report all errors including syntax to the browser. > Such errors must always be preceded by a "Content-type: text/html\n\n" > > I don't want to use the CGI module, because I consider this to be > overkill for the small script I am writing. You can - catch exceptions from require (as Brian pointed out). - replace STDERR (or $stderr) by a StringOut (maybe it has a different name) and see whether it contains something in which case you report it back to the client. You don't need to fuddle with class Exception at all. Apart from that: Syntax errors in skript are normally program errors which you don't want to report to the client because they should not occur after testing; if they do occur, an exception dump and / or a log entry is good enough. Of course, if a user may provide a script that you want to execute he want's to get informed of such errors. But this is - as you might have guessed - a dangerous thing to do... Regards robert