[C++-sig] Custom Exception objects

John A Meinel john at arbash-meinel.com
Tue Nov 2 23:52:09 CET 2004


I was wondering how to handle custom exception objects using boost::python.

I know about doing this:

static void translateConfigError(ConfigError const &e) {
	PyErr_SetString(PyExc_RuntimeError, e.what());
}
register_exception_translator<ConfigError>(&translateConfigError);

However, as far as I know, this only lets you translate a C++ exception 
class into a standard Python exception class.

Since I have already wrapped ConfigError as a boost::python class, is it 
possible to do something more like:

static void translateConfigError(ConfigError const &e) {
	PyErr_SetString(my_python_exception, e.what());
}

where my_python_exception was somehow related to ConfigError?

It is nice that I can at least generate KeyError, or ValueError, 
SyntaxError, etc, but it would be nice if I could generate ConfigError.

John
=:->
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 253 bytes
Desc: OpenPGP digital signature
URL: <http://mail.python.org/pipermail/cplusplus-sig/attachments/20041102/da9db3a7/attachment.pgp>


More information about the Cplusplus-sig mailing list