[C++-sig] Wrapper for exception translation

Gottfried.Ganssauge at HAUFE.DE Gottfried.Ganssauge at HAUFE.DE
Wed Jul 9 19:23:48 CEST 2003


Hi everyone,

for my current project I was in need for a simple method to make user
defined exceptions within my module.
The basic framework in the form of exception translation is there so I only
needed to make it a bit more accessible.
I made a template function exception_<Exception> (const char *name) which
creates a python exception and an instance of templated translation handler.
The translation handler instance is held in the python translation's class
dictionary as the __handler__ attribute.
Then the handler is registered as an exception translator for the Exception
using register_exception_translator().
The python exception object is finally registered in the current scope's
dictionary using the "name" argument to exception_().

To register an exception translator for exception e you simply call
exception_<e> ("e") within your module init function.

This implementation is quite usable for me but I would be totally glad if it
could somehow be integrated with pyste.

I tested it with gcc-3.2, gcc-3.3 and gcc-2.95

Cheers,

Gottfried

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/cplusplus-sig/attachments/20030709/947efa68/attachment.htm>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: except.cpp
Type: application/octet-stream
Size: 767 bytes
Desc: not available
URL: <http://mail.python.org/pipermail/cplusplus-sig/attachments/20030709/947efa68/attachment.obj>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: except.h
Type: application/octet-stream
Size: 4096 bytes
Desc: not available
URL: <http://mail.python.org/pipermail/cplusplus-sig/attachments/20030709/947efa68/attachment-0001.obj>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: test_exc.py
Type: application/octet-stream
Size: 387 bytes
Desc: not available
URL: <http://mail.python.org/pipermail/cplusplus-sig/attachments/20030709/947efa68/attachment-0002.obj>


More information about the Cplusplus-sig mailing list