Subj : Re: How do I raise an exception? To : netscape.public.mozilla.jseng From : Rob Swindell Date : Sat Aug 06 2005 01:31 am "Thomas Sondergaard" wrote in message news:42f08b09$0$2350$edfadb0f@dread11.news.tele.dk... > Rob Swindell wrote: >> I use JS_ReportError and it seems to work fine. Example: >> >> if((p=(private_t*)malloc(sizeof(private_t)))==NULL) { >> JS_ReportError(cx,"malloc failed"); >> return(JS_FALSE); >> } >> > > It doesn't work for me. The error reported with JS_ReportError is passed > to the error reporter I have configured with JS_SetErrorReporter, but I > don't get a catchable exception my script just exits. I'm sorry, I was mistaken. The following does throw an exception however: if((p=(private_t*)malloc(sizeof(private_t)))==NULL) { JS_SetPendingException(cx,argv[0]); return(JS_FALSE); } > I tried printing the value returned by JS_IsExceptionPending after calling > JS_ReportError, like this: > > JS_ReportError(ctx, "Invalid argument - not an int"); > cerr << "after JS_ReportError: " << JS_IsExceptionPending(ctx) << endl; > > .. and it tells me that an exception is not pending. > > Under what conditions will JS_ReportError not raise an exception? Apparently never. :-( -Rob .