exceptions
Martin Klang <[email protected]> Mon, 12 May 2003 16:40:22 +0000 (GMT)
| Newsgroups | gmane.text.xml.o-xml |
|---|---|
| Message-ID | <[email protected]> |
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1
Hi, this is mainly a request for comments -
I've been doing some work on exception handling lately. Although not yet
covered in the spec, I see it working something like this:
<o:catch exceptions="SystemError, ex:Error" handler="ExceptionHandler()">
... do stuff ...
<o:throw select="Exception('get me out of here')"/>
</o:catch>
The 'exceptions' attribute takes a comma-separated list of type names
(QNames). If one is not present, the default is to catch all exceptions.
If an exception is thrown within the body of the catch block that is _not_
in the (non-empty) list, it will simply pass through.
The handler is used instead of the normal Java/C++ catch block - it must
be an expression that evaluates to an object that defines a 'handle(Node)'
function. The default expression is 'ExceptionHandler()', ie the default
handlers constructor. The default handler only prints a log output of the
error caught.
Defining and throwing exceptions can be done just like in Java, with the
difference that anything can be an exception. You can throw a string
<o:throw select="'aeroplane'"/> or a number or anything.
Exception handlers can be created to derive from ExceptionHandler with
specialised functions for certain types of exceptions, using the dynamic
function overloading abilities of o:XML ->
<o:type name="MyHandler">
<o:parent name="ExceptionHandler"/>
<o:function name="handle">
<o:param name="exception" type="SystemError"/>
<o:do>
handle system errors only
</o:do>
</o:function>
</o:type>
though deriving from ExceptionHandler is not always required.
SystemErrors are thrown when somethings gone bad beyond repair - for
example an undefined variable, unknown type name, invalid expression etc.
Exception handling also links in with assertions.
I've added another mapping, assert:
<o:assert test="$var < 5"/>
and an error type: AssertionError
Both AssertionError and SystemError derive from the type Exception.
All the functionality described above is now in CVS.
there's a working example in the cvs tree:
http://cvs.pingdynasty.com/cgi-bin/cvsweb.cgi/ObjectBox/examples/throw.oml?rev=1.2&content-type=text/x-cvsweb-markup
If you would like to try it out but don't have access to CVS, let me know
and I'll make the src/binaries available.
I aim to include exceptions and assertions in the next release. Its an
important part of any language and critical to get right - your comments
and suggestions will be invaluable.
best regards,
/m
Martin Klang
http://www.o-xml.org - the object-oriented XML programming language
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.0.6 (GNU/Linux)
Comment: For info see http://www.gnupg.org
iD8DBQE+v853U02Ml0598n4RAkrBAJ9peBlJsk12afYIRwZpQtX2SYuZ3gCeNUyi
5Jw0w0LW+hnxVwviaq23N9w=
=e6Sk
-----END PGP SIGNATURE-----