diff --git a/api-testcases/test-throw.c b/api-testcases/test-throw.c new file mode 100644 index 00000000..195497c0 --- /dev/null +++ b/api-testcases/test-throw.c @@ -0,0 +1,17 @@ +/*=== +rc=1 -> throw me +===*/ + +int test_1(duk_context *ctx) { + duk_push_string(ctx, "throw me"); + duk_throw(ctx); + return 0; +} + +void test(duk_context *ctx) { + int rc; + + rc = duk_safe_call(ctx, test_1, 0, 1, DUK_INVALID_INDEX); + printf("rc=%d -> %s\n", rc, duk_get_string(ctx, -1)); +} + diff --git a/website/api/duk_throw.txt b/website/api/duk_throw.txt new file mode 100644 index 00000000..25c76a1d --- /dev/null +++ b/website/api/duk_throw.txt @@ -0,0 +1,17 @@ +=proto +void duk_throw(duk_context *ctx); + +=stack +[ ... val! ] + +=summary +

Throw the value on top of the stack. This call never returns.

+ +=example +/* Throw a string value; equivalent to the Ecmascript code: + * + * throw "this string is thrown"; + */ + +duk_push_string(ctx, "this string is thrown"); +duk_throw(ctx);