[IronPython] Dealing with exceptions in an extension module

Lukas Cenovsky cenovsky at bakalari.cz
Sat May 1 07:43:32 CEST 2010


Dino Viehland wrote:
> 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.

Speaking about exceptions. Is there a way to convert the 
System.Exception to the Python exception when I know the 
System.Exception is a Python exception?

I ran into this when I played with data binding and 
BindingValidationError event. This event is raised when a setter throws 
an exception. So I threw MyException. But in the event, the 
event.Error.Exception is System.Exception and I couldn't figured out how 
to access the Python properties in this "MyException".

--
-- Lukás(
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/ironpython-users/attachments/20100501/4b0c0910/attachment.html>


More information about the Ironpython-users mailing list