From 692a7c4c7ffba171ebb66a31b674e9f117df1fe2 Mon Sep 17 00:00:00 2001 From: Jo-Philipp Wich Date: Mon, 21 Sep 2020 13:25:53 +0200 Subject: tests: add try/catch testcase Signed-off-by: Jo-Philipp Wich --- tests/02_runtime/03_try_catch | 31 +++++++++++++++++++++++++++++++ 1 file changed, 31 insertions(+) create mode 100644 tests/02_runtime/03_try_catch (limited to 'tests/02_runtime') diff --git a/tests/02_runtime/03_try_catch b/tests/02_runtime/03_try_catch new file mode 100644 index 0000000..518c1f1 --- /dev/null +++ b/tests/02_runtime/03_try_catch @@ -0,0 +1,31 @@ +Wrapping an exeptional operation in try {} catch {} allows handling the +resulting exception and to continue the execution flow. + +-- Expect stdout -- +Catched first exception. +Catched second exception: exception 2. +After exceptions. +-- End -- + +-- Testcase -- +{% + // A try-catch block that discards the exception information. + try { + die("exception 1"); + } + catch { + print("Catched first exception.\n"); + } + + // A try-catch block that captures the resulting exception in + // the given variable. + try { + die("exception 2"); + } + catch (e) { + print("Catched second exception: ", e, ".\n"); + } + + print("After exceptions.\n"); +%} +-- End -- -- cgit v1.2.3