Subj : Re: Error handling To : Braden McDaniel From : Brendan Eich Date : Sun May 11 2003 11:22 am >>Errors other than "out of memory" become exceptions. >> >> > >"Become"? Does that mean an exception is thrown as a result of calling >JS_ReportError? What exception? > Lxr for JS_HAS_ERROR_EXCEPTIONS. Reporting an error throws an exception. The type and details depend on the parameters you put in your .msg file. You'll want to look at js.msg and jsshell.msg and imitate those. Also see where they're #included with an appropriate MSG_DEF macro definition inside an array initializer, to initialize the js_ErrorFormatString table in jscntxt.c, e.g. >> If you need >>localizable error messages, you'll have to supply your own >>JSErrorCallback (see js.c for an example). >> >> > >You mean JSErrorReporter? > No, I mean a (const JSErrorFormatString *)-returning callback function such as js_GetErrorMessage in jscntxt.c, or my_GetErrorMessage in js.c. >> If you want to signal >>conditions other than errors, you can throw objects or primitive values, >>however you please. >> >> > >The particular conditions I'm dealing with now are: > > * Insufficent number of arguments to a function. > * Inappropriate type passed to function. > >For the latter, I think I want to throw a TypeError. >(JS_SetPendingException, right?) I'm not sure about the former; does it >qualify as a condition other than an error? > No, it sounds like an error. Use JSEXN_TYPEERR in your js.msg clone for type errors. /be .