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 --


Ensure that exceptions are propagated through C function calls.

-- Expect stderr --
exception
In [anonymous function](), line 3, byte 18:
  called from function replace ([C])
  called from anonymous function ([stdin]:4:3)

 `        die("exception");`
  Near here -------------^


-- End --

-- Testcase --
{%
	replace("test", "t", function(m) {
		die("exception");
	});
%}
-- End --


Ensure that exception can be catched through C function calls.

-- Expect stdout --
Caught exception: exception
-- End --

-- Testcase --
{%
	try {
		replace("test", "t", function(m) {
			die("exception");
		});
	}
	catch (e) {
		print("Caught exception: ", e, "\n");
	}
%}
-- End --


Ensure that exceptions are propagated through user function calls.

-- Expect stderr --
exception
In a(), line 3, byte 18:
  called from function b ([stdin]:7:5)
  called from function c ([stdin]:11:5)
  called from anonymous function ([stdin]:14:4)

 `        die("exception");`
  Near here -------------^


-- End --

-- Testcase --
{%
	function a() {
		die("exception");
	}

	function b() {
		a();
	}

	function c() {
		b();
	}

	c();
%}
-- End --


Ensure that exceptions can be caught in parent functions.

-- Expect stdout --
Caught exception: exception
-- End --

-- Testcase --
{%
	function a() {
		die("exception");
	}

	function b() {
		a();
	}

	function c() {
		try {
			b();
		}
		catch (e) {
			print("Caught exception: ", e, "\n");
		}
	}

	c();
%}
-- End --