JS_SetErrorReporter

  • Revision slug: SpiderMonkey/JSAPI_Reference/JS_SetErrorReporter
  • Revision title: JS_SetErrorReporter
  • Revision id: 138658
  • Created:
  • Creator: Jorend
  • Is current revision? No
  • Comment 17 words added

Revision Content

Specify the error reporting mechanism for an application.

Syntax

JSErrorReporter JS_SetErrorReporter(JSContext *cx, JSErrorReporter er);
Name Type Description
cx JSContext * Pointer to a JS context from which to derive runtime information.
er JSErrorReporter The user-defined error reporting function to use in your application, described below.

Callback Syntax

typedef void (*JSErrorReporter)(
    JSContext *cx, const char *message, JSErrorReport *report);
Name Type Description
cx JSContext * The context in which the error happened.
message const char * An error message.
report JSErrorReport * An error report record containing additional details about the error.

Description

JS_SetErrorReporter enables you to define and use your own error reporting mechanism in your applications. The reporter you define is automatically passed a JSErrorReport structure when an error occurs and has been parsed by JS_ReportError.

Typically, the error reporting mechanism you define should log the error where appropriate (such as to a log file), and display an error to the user of your application. The error you log and display can make use of the information passed about the error condition in the JSErrorReport structure.

The error reporter callback must not reenter the JSAPI in a way that might allocate memory. Like all other SpiderMonkey callbacks, the error reporter callback must not throw a C++ exception.

{{ LXRSearch("ident", "i", "JS_SetErrorReporter") }}

Revision Source

<p>Specify the error reporting mechanism for an application.
</p>
<h2 name="Syntax"> Syntax </h2>
<pre class="eval"><a href="/en/SpiderMonkey/JSAPI_Reference/JS_SetErrorReporter" title="en/JS_SetErrorReporter">JSErrorReporter</a> <strong>JS_SetErrorReporter</strong>(<a href="/en/SpiderMonkey/JSAPI_Reference/JSRuntime" title="en/JSRuntime">JSContext</a> *cx, <a href="/en/SpiderMonkey/JSAPI_Reference/JS_SetErrorReporter" title="en/JS_SetErrorReporter">JSErrorReporter</a> er);
</pre>
<table class="fullwidth-table">
<tbody><tr>
<th>Name</th>
<th>Type</th>
<th>Description</th>
</tr>
<tr>
<td><code>cx</code></td>
<td><code><a href="/en/SpiderMonkey/JSAPI_Reference/JSRuntime" title="en/JSRuntime">JSContext</a> *</code></td>
<td>Pointer to a JS context from which to derive runtime information.</td>
</tr>
<tr>
<td><code>er</code></td>
<td><code><a href="/en/SpiderMonkey/JSAPI_Reference/JS_SetErrorReporter" title="en/JS_SetErrorReporter">JSErrorReporter</a></code></td>
<td>The user-defined error reporting function to use in your application, described below.</td>
</tr>
</tbody></table>
<h3 name="Callback_Syntax"> Callback Syntax </h3>
<pre class="eval">typedef void (*<strong>JSErrorReporter</strong>)(
    <a href="/en/SpiderMonkey/JSAPI_Reference/JSRuntime" title="en/JSRuntime">JSContext</a> *cx, const char *message, <a href="/en/SpiderMonkey/JSAPI_Reference/JSErrorReport" title="en/JSErrorReport">JSErrorReport</a> *report);
</pre>
<table class="fullwidth-table">
<tbody><tr>
<th>Name</th>
<th>Type</th>
<th>Description</th>
</tr>
<tr>
<td><code>cx</code></td>
<td><code><a href="/en/SpiderMonkey/JSAPI_Reference/JSRuntime" title="en/JSRuntime">JSContext</a> *</code></td>
<td>The context in which the error happened.</td>
</tr>
<tr>
<td><code>message</code></td>
<td><code>const char *</code></td>
<td>An error message.</td>
</tr>
<tr>
<td><code>report</code></td>
<td><code><a href="/en/SpiderMonkey/JSAPI_Reference/JSErrorReport" title="en/JSErrorReport">JSErrorReport</a> *</code></td>
<td>An error report record containing additional details about the error.</td>
</tr>
</tbody></table>
<h2 name="Description">Description</h2>
<p><code>JS_SetErrorReporter</code> enables you to define and use your own error reporting mechanism in your applications. The reporter you define is automatically passed a <code><a href="/en/SpiderMonkey/JSAPI_Reference/JSErrorReport" title="en/JSErrorReport">JSErrorReport</a></code> structure when an error occurs and has been parsed by <code><a href="/en/SpiderMonkey/JSAPI_Reference/JS_ReportError" title="en/JS_ReportError">JS_ReportError</a></code>.</p>
<p>Typically, the error reporting mechanism you define should log the error where appropriate (such as to a log file), and display an error to the user of your application. The error you log and display can make use of the information passed about the error condition in the <code>JSErrorReport</code> structure.</p>
<p>The error reporter callback must not reenter the JSAPI in a way that might allocate memory. Like all other SpiderMonkey callbacks, the error reporter callback must not throw a C++ exception.</p>
<p>{{ LXRSearch("ident", "i", "JS_SetErrorReporter") }}</p>
Revert to this revision