[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [Xen-devel] python bindings: xen.lowlevel.xc.error



On Thursday 18 May 2006 3:14 pm, Ewan Mellor wrote:
> On Thu, May 18, 2006 at 12:31:53PM -0700, Kaleb Pederson wrote:
[snip]
>
> They are exceptions of the built-in type RuntimeError -- that's what you
> get when you use PyErr_SetFromErrno in the C layer.  I don't know why it
> shows up as xc.error -- presumably that's a Python internal thing.

So this should work, but doesn't either:

>>> import xen.lowlevel.xc as xc
>>> import exceptions
>>> x = xc.xc()
>>> try:
...     x.bvtsched_domain_get(0)
... except exceptions.RuntimeError, e:
...     print "Caught RuntimeError"
...
Traceback (most recent call last):
  File "<stdin>", line 2, in ?
xen.lowlevel.xc.error: (22, 'Invalid argument')

I also confirmed with isinstance, and exception is the only one of 
exceptions.* that it inherits from.

I'm not familiar with the Python C API at all, but I did a bit of digging 
around:

from tools/python/xen/lowlevel/xc/xc.c:

...
#define PKG "xen.lowlevel.xc"
...
    xc_error = PyErr_NewException(PKG ".error", NULL, NULL);
...

So, the name displayed (xen.lowlevel.xc.error) is defined based on the call 
above.  I found the python docs for PyErr_NewException:

"
PyObject* PyErr_NewException(  char *name, PyObject *base, PyObject *dict)
Return value: New reference. 
 This utility function creates and returns a new exception object. The name 
argument must be the name of the new exception, a C string of the form 
module.class. The base and dict arguments are normally NULL. This creates a 
class object derived from the root for all exceptions, the built-in name 
Exception (accessible in C as PyExc_Exception). The __module__ attribute of 
the new class is set to the first part (up to the last dot) of the name 
argument, and the class name is set to the last part (after the last dot). 
The base argument can be used to specify an alternate base class. The dict 
argument can be used to specify a dictionary of class variables and methods.
"

So, per the docs, it is only derived from Exception.  It would be much nicer 
if it were derived from some other exception class... say XenException or 
something....

Thanks.

--Kaleb

Attachment: pgpPvZA8F3f2E.pgp
Description: PGP signature

_______________________________________________
Xen-devel mailing list
Xen-devel@xxxxxxxxxxxxxxxxxxx
http://lists.xensource.com/xen-devel

 


Rackspace

Lists.xenproject.org is hosted with RackSpace, monitoring our
servers 24x7x365 and backed by RackSpace's Fanatical Support®.