JS::AutoSaveExceptionState

This article covers features introduced in SpiderMonkey 31

Save and later restore the current exception state of a given JSContext.

Syntax

JS::AutoSaveExceptionState(JSContext *cx);
Name Type Description
cx JSContext * Pointer to a JS context from which to derive runtime information. Requires request. In a JS_THREADSAFE build, the caller must be in a request on this JSContext.

Description

JS::AutoSaveExceptionState saves and later restores the current exception state of a given JSContext.

This is useful for implementing behavior in C++ that's like try/catch or try/finally in JS.

Example

// Typical usage:
bool ok = JS::Evaluate(cx, ...);
AutoSaveExceptionState savedExc(cx);
... cleanup that might re-enter JS ...
return ok;

 

See Also

Document Tags and Contributors

Contributors to this page: kscarfone, arai
Last updated by: kscarfone,