I've opted for a quite simple solution. The compiler/VM only has a simple try/catch statement to capture any exception and unwind the stack.
The application can then register its own methods for throwing exceptions explicitly and for inspecting caught exceptions. The standard add-on of course come with a couple of pre-implemented solutions that the applications can use if you prefer not to implement your own.
Here's the excerpt from the doxygen source for the WIP version:
\section try Try-catch blocks
<pre>
{
try
{
DoSomethingThatMightThrowException();
// This is not executed if an exception was thrown
}
catch
{
// This is executed if an exception was thrown
}
}
</pre>
A try-catch block can be used if you're executing some code that might throw an exception
and you want to catch that exception and continue with the exception rather than just abort
the script.
\subsection try_func Functions
\note The standard <tt>throw</tt> and <tt>getExceptionInfo</tt> are only
provided if the application \ref doc_addon_helpers_try "registers them".
<b>void throw(const string &in exception)</b>
Explicitly throw an exception. The string should identify the type of exception, for logging or treating.
<b>string getExceptionInfo()</b>
Get the exception string for the last exception thrown.
One enhancement over the standard add-on that I can think of is to allow the throw and getExceptionInfo carry a dictionary with further information on the exception, e.g. location, callstack, and perhaps user defined parameters.