[DB-SIG] Remaining issues with DB API 2.0

M.-A. Lemburg mal@lemburg.com
Thu, 01 Apr 1999 11:38:13 +0200

Andy Dustman wrote:
> > I'd say we make two subclasses of Error: InterfaceError, and
> > DatabaseError.
> Speaking of which, I can't find a obvious way in the Python API to create
> an exception with multiple inheritance. Any ideas?

You mean: how do I create an exception having a predefined base class ?
[I don't see a need for multiple inheritance (with more than one
base class) in this situation.]

Here's an example:

/* Create an exception object, insert it into the module dictionary
   under the given name and return the object pointer; this is NULL in
   case an error occurred. base can be given to indicate the base
   object to be used by the exception object. It should be NULL
   otherwise */

PyObject *insexc(PyObject *moddict,
		 char *name,
		 PyObject *base)
    PyObject *v;
    char fullname[256];
    v = PyErr_NewException(fullname, base, NULL);
    if (v == NULL)
	return NULL;
    if (PyDict_SetItemString(moddict,name,v))
	return NULL;
    return v;


    if ((mxODBC_Error = insexc(moddict,"Error",PyExc_StandardError)) == NULL)
	goto onError;
    if ((mxODBC_InterfaceError = insexc(moddict,"InterfaceError",mxODBC_Error))
	== NULL)
	goto onError;

Was that what you meant ?

Marc-Andre Lemburg                               Y2000: 274 days left
          : Python Pages >>> http://starship.skyport.net/~lemburg/  :