mirror of https://github.com/svaarala/duktape.git
You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
48 lines
1.1 KiB
48 lines
1.1 KiB
name: duk_safe_to_stacktrace
|
|
|
|
proto: |
|
|
const char *duk_safe_to_stacktrace(duk_context *ctx, duk_idx_t idx);
|
|
|
|
stack: |
|
|
[ ... val! ... ] -> [ ... val.stack! ... ]
|
|
|
|
summary: |
|
|
<p>Like <code><a href="#duk_to_stacktrace">duk_to_stacktrace()</a></code>
|
|
but if the coercion fails, duk_to_stacktrace() is applied to the coercion
|
|
error. If that also fails, a fixed pre-allocated error string <code>"Error"</code>
|
|
is used instead (because the string is pre-allocated, this cannot fail due to
|
|
out-of-memory).</p>
|
|
|
|
<p>ECMAScript equivalent:</p>
|
|
<pre class="ecmascript-code">
|
|
function duk_safe_to_stacktrace(val) {
|
|
try {
|
|
return duk_to_stacktrace(val);
|
|
} catch (e) {
|
|
try {
|
|
return duk_to_stacktrace(e);
|
|
} catch (e2) {
|
|
return 'Error';
|
|
}
|
|
}
|
|
}
|
|
</pre>
|
|
|
|
example: |
|
|
if (duk_peval_string(ctx, "1 + 2 +") != 0) { /* => SyntaxError */
|
|
printf("failed: %s\n", duk_safe_to_stacktrace(ctx, -1));
|
|
} else {
|
|
printf("success\n");
|
|
}
|
|
duk_pop(ctx);
|
|
|
|
tags:
|
|
- stack
|
|
- string
|
|
- protected
|
|
|
|
seealso:
|
|
- duk_safe_to_string
|
|
- duk_to_stacktrace
|
|
|
|
introduced: 2.4.0
|
|
|