I've recently downloaded the .Net extensions for Python, and I've found
some bugs regarding constructors and exceptions.
My test code is below, with two classes. The first takes a single
integer argument, and generates a division by zero exception if this is
zero. The second class will always generate an exception. Both
constructors will write a line to stdout when run.
MyTest.cs:
----------------------------------------------------------------------
using System;
using System.Collections;
using System.Management;
namespace MyTest
{
public class Bad
{
public Bad(int i)
{
Console.WriteLine("Test");
int i2 = 1;
int i1 = i;
i2 = i2 / i1;
}
}
public class Bad2
{
public Bad2()
{
Console.WriteLine("Test");
int i2 = 1;
int i1 = 0;
i2 = i2 / i1;
}
}
}
----------------------------------------------------------------------
test.py:
----------------------------------------------------------------------
import CLR.MyTest
import sys, traceback
try:
print repr(CLR.MyTest.Bad(1))
except:
print '-'*60
traceback.print_exc()
print '-'*60
try:
print repr(CLR.MyTest.Bad(0))
except:
print '-'*60
traceback.print_exc()
print '-'*60
try:
print repr(CLR.MyTest.Bad2())
except:
print '-'*60
traceback.print_exc()
print '-'*60
try:
print repr(CLR.MyTest.Bad2(1))
except:
print '-'*60
traceback.print_exc()
print '-'*60
----------------------------------------------------------------------
Output from test.py:
----------------------------------------------------------------------
Test