[prev in list] [next in list] [prev in thread] [next in thread] 

List:       kfm-devel
Subject:    Re: regexp error..
From:       Peter Kelly <pmk () post ! com>
Date:       2001-11-03 11:45:23
[Download RAW message or body]

Assuming you are doing this from a call() or get() method or similar, you 
would use something like the following:

UString m = I18N_NOOP("Invalid variable type");
Object err = Error::create(exec, TypeError, m.ascii());
exec->setException(err);
return err;

Pretty soon after you return, one of the methods in nodes.cpp will do a 
KJS_CHECKEXCEPTION and see that an exception has occurred and take it from 
there. If your method is normally being called from somewhere outside of 
nodes.cpp, you may want to make sure that it is also checking for the 
exception right after your method returns, so that code that is supposed 
to be executed after your method gets skipped and execution goes right to 
the appropriate catch() clause (if one is present).

If you want to throw the exception from within nodes.cpp, and your method 
is supposed to return a Completion object, then the Completion(Throw,...) 
you described is correct.

On Fri, 2 Nov 2001, Michael Bedy wrote:

> 
>   How do I throw an error in Javascript if the regular expression is bad?
> I'm not sure I quite get that part of the interpreter.....
> 
>   For instance, if the flags are incorrect, I need to throw a syntax
> error. Does Completion(Throw, throwError(exec, SyntaxError, "Bad regex
> flags")) produce an object that can be returned from the construct
> function? Is that all I have to do to throw an exception?
> 
>    Thanks,
>     - Mike
> 
> 

-- 
Peter Kelly
pmk@post.com

[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic