[IronPython] Dealing with exceptions in an extension module

Dino Viehland dinov at microsoft.com
Fri Apr 30 15:10:02 PDT 2010


Jeff wrote:
> I'm trying to fix up the exceptions for the _sqlite3 module I'm
> implementing. The dbapi spec (PEP 249) requires a very specific
> exception hierarchy, including exceptions derived from StandardError.
> 
> My initial version just used C# Exception classes, but StandardError
> is not a normal class, so that was insufficient. I looked into how the
> existing modules did it (using PythonContext.EnsureModuleException)
> and started to implement that but I've run up against a bit of a
> roadblock: PythonExceptions.CreateThrowable is internal. It's not a
> problem for anything in IronPython.Modules, of course, because of the
> accursed InternalsVisibleToAttribute, but that doesn't help me much
> :).
> 
> Is there a public way to create and throw a Python exception (i.e. a
> BaseException instance)? For now I'm just using reflection, but I
> would like a better way.

There's a public PythonOps.CreateThrowable.  It just forwards the call
to the internal PythonExceptions.CreateThrowable.

> 
> On a related note, there's too much stuff that's used in
> IronPython.Modules but is internal in IronPython - it makes it hard to
> figure out the "proper" (public) way to do things.

Yeah, maybe we should remove the internals visible to and make everything
it relies on public.  I think I'd be mostly alright with that but there
might be a few places where we suffer (like not having access to our AddNoLock
methods for appending to lists).




More information about the Users mailing list