Links

Categories

Tags

bass bindings blog changes log code debugger demo discussion documentation embedding example jewel++ native types news overview release resumee tutorial update

« Garbage collection in JewelScript | Main | Testing a programming language »

Basic exceptions added

By jewe | February 15, 2010

I’ve added basic support for exceptions to the language. Support for exceptions has been in the runtime from the beginning, however, it was never really used – except for the debugger which intercepts and shows them. But you had no way of using them from within the language. Until now.

In the new version, there is basic support for exceptions, which means there is now a throw statement that lets you throw an exception.

There is also a built-in interface for exceptions.

strict interface exception {
    method exception();
    method exception(int error);
    method int getError();
}

In order to throw an exception, you’ll have to make a class that implements this interface. After that, you can use the throw statement to throw an instance of your exception class. Needless to say, you can add any amount of additional members to your exception class.

If you throw, the whole stack will automatically be unrolled to the most recent native entry-point. The JILCallFunction() method will return the handle to your exception object instead of the function’s result.

You can use the NTLHandleToError() function to test whether the result is an exception object or a regular function result. The function will actually call the getError() method of your script object and return it’s result as error code to the caller.

There is no way of catching exceptions from script code, yet. And I doubt there will be any for the release of version 1.0. However, I’m planning to add support for try / catch in a later release.

You probably wonder now what’s the use of the throw statement then. Well, it allows you to instantly end a call from the native world to the script world and pass an error object, no matter how deep inside nested function calls you currently are.

Of course this also works with multiple nested native -> script -> native -> script calls, as long as the involved native code properly propagates the error status up to their caller. Therefore this is also useful to exit delegates that are executed from native type functions.

For an example, see this small JewelScript file.

Topics: news | No Comments »

Comments

You must be logged in to post a comment.