From:  "Berserker" <raffaele.romito@gmail.com>
Date:  30 Jun 2006 21:52:26 Hong Kong Time
Newsgroup:  news.mozilla.org/netscape.public.mozilla.jseng
Subject:  

Re: Exceptions handling

NNTP-Posting-Host:  62.101.126.235

Ok, I found a solution by myself ;)

static JSBool alfa(JSContext *cx, JSObject *obj, uintN argc, jsval
*argv, jsval *rval)
{
	return JS_TRUE;
}

static JSBool beta(JSContext *cx, JSObject *obj, uintN argc, jsval
*argv, jsval *rval)
{
	return JS_TRUE;
}

typedef JSBool (* callback_type)(JSContext *cx, JSObject *obj, uintN
argc, jsval *argv, jsval *rval);

template 
static JSBool hook(JSContext *cx, JSObject *obj, uintN argc, jsval
*argv, jsval *rval)
{
	try
	{
		// The trick i here :<>

		return reinterpret_cast(T)(cx, obj, argc, argv, rval);
	}
	catch(std::exception &e)
	{
		JS_SetPendingException(cx, JSVAL_VOID);
	}

	return JS_FALSE;
}

void register_functions(JSContext *cx, JSObject *obj)
{
        JSFunctionSpec methods[] =
                                        {
                { "alfa", hook, 0, 0, 0 },
                { "beta", hook, 0, 0, 0 },
                { 0, 0, 0, 0, 0 }
        };
        JS_DefineFunctions(cx, obj, methods); 
}

What about?