From a9c7257beaf8eeef25fddd3b8bf87b51de158f69 Mon Sep 17 00:00:00 2001
From: Sami Vaarala duk_push_error_object()
.
Even though the function never returns, the prototype describes a return + value which allows code such as:
++ if (argvalue < 0) { + return duk_error(ctx, DUK_ERR_TYPE_ERROR, "invalid argument value: %d", (int) argvalue); + } ++ example: | duk_error(ctx, DUK_ERR_RANGE_ERROR, "argument out of range: %d", (int) argval); diff --git a/website/api/duk_error_va.yaml b/website/api/duk_error_va.yaml index 2bc51566..1b3aefe7 100644 --- a/website/api/duk_error_va.yaml +++ b/website/api/duk_error_va.yaml @@ -1,7 +1,7 @@ name: duk_error_va proto: | - void duk_error_va(duk_context *ctx, duk_errcode_t err_code, const char *fmt, va_list ap); + duk_ret_t duk_error_va(duk_context *ctx, duk_errcode_t err_code, const char *fmt, va_list ap); stack: | [ ... ] -> [ ... err! ] diff --git a/website/api/duk_fatal.yaml b/website/api/duk_fatal.yaml index 253754c0..d147acf9 100644 --- a/website/api/duk_fatal.yaml +++ b/website/api/duk_fatal.yaml @@ -1,7 +1,7 @@ name: duk_fatal proto: | - void duk_fatal(duk_context *ctx, const char *err_msg); + duk_ret_t duk_fatal(duk_context *ctx, const char *err_msg); summary: |
Call fatal error handler with an optional message (err_msg
@@ -14,6 +14,13 @@ summary: |
You should only call this function when a truly fatal, unrecoverable error
has occurred.
Even though the function never returns, the prototype describes a return + value which allows code such as:
++ if (argvalue < 0) { + return duk_fatal(ctx, "argvalue invalid, cannot continue execution"); + } + example: | duk_fatal(ctx, "assumption failed"); diff --git a/website/api/duk_throw.yaml b/website/api/duk_throw.yaml index 9c546323..09c83e90 100644 --- a/website/api/duk_throw.yaml +++ b/website/api/duk_throw.yaml @@ -1,7 +1,7 @@ name: duk_throw proto: | - void duk_throw(duk_context *ctx); + duk_ret_t duk_throw(duk_context *ctx); stack: | [ ... val! ] @@ -9,6 +9,15 @@ stack: | summary: |Throw the value on top of the stack. This call never returns.
+Even though the function never returns, the prototype describes a return + value which allows code such as:
++ if (argvalue < 0) { + duk_push_error_object(ctx, DUK_ERR_TYPE_ERROR, "invalid argument: %d", (int) argvalue); + return duk_throw(ctx); + } ++ example: | /* Throw a string value; equivalent to the Ecmascript code: *