Subj : Re: Constructor function cleanly failing To : netscape.public.mozilla.jseng From : Shanti Rao Date : Mon Jan 10 2005 09:49 am Matthew Mondor wrote: > Hi all, > > I was wondering if it is possible for a constructor function for a class > to return with an error to notify the script, although not causing > script execution to stop? Must object creation with "new" always > succeed for a script to continue in ECMAScript? > You can trap exceptions in the calling code, like var a; try { a = new Foo() } catch(x) {} The exception (x) can have extra information passed from your constructor. JS_SetPendingException(cx,STRING_TO_JSVAL(JS_NewStringCopyZ(cx,"Error description"))); *rval = OBJECT_TO_JSVAL(NULL); return JS_FALSE; .