General Interface extends the native JavaScript exception facilities in several ways that make it easier to build and debug large applications. General Interface defines the jsx3.lang.Exception class, which extends jsx3.lang.Object and is the superclass of all General Interface exceptions. This base class is stack aware, which means that it stores the call stack at the point where it was created. By using and/or extending jsx3.lang.Exception, you can take advantage of some features of exceptions that exist in more advanced languages such as Java. Several methods in the General Interface Framework throw exceptions to communicate to the caller that an error has occurred. Note that some classes, such as jsx3.xml.Document, fail silently by storing error information in instance fields rather than throwing exceptions. General Interface Framework methods that throw a General Interface exception are documented in the API Documentation (Help>API Documentation). Such methods should be surrounded by a try...catch block to prevent the exception from reaching the top of the call stack. Because exceptions in JavaScript aren't checked as they are in Java, if a method that throws an exception isn't surrounded with a try...catch block, it's not a compilation error. General Interface also defines jsx3.lang.NativeError, a subclass of jsx3.lang.Exception, which wraps the native browser exception object. NativeError is a cross-platform interface onto the exceptions that the browser may raise. Since NativeError extends Exception, application code can treat all exceptions caught in a try...catch block as instances of the Exception class. This is accomplished with the following code: try { doSomething(); } catch (e) { // e may be a native browser Error object or an instance of // jsx3.lang.Exception thrown by application or framework code var ex = jsx3.lang.NativeError.wrap(e); window.alert(ex.printStackTrace()); } Finally, in General Interface Builder and when error trapping is enabled in running General Interface applications, any error that reaches the top of the stack and the browser is routed to the General Interface logging system. The exception will be sent to the global logger, jsx3.util.Logger.GLOBAL, with severity ERROR. |
Contents
|
