[Python.NET] Why are default constructors called on exceptions?

Chris Gagnon cgagnon at zindagigames.com
Tue Dec 15 04:02:12 CET 2009


 Consider this C# library

namespace MyLib
> {
>     public class CXDoc
>     {
>         // Construction
>         public CXDoc(string sPath)
>         {
>             XmlDocument oDoc = new XmlDocument();
>             oDoc.Load(sPath);
>         }
>         public CXDoc()
>         {
>             throw new Exception("Deprecated constructor.");
>         }
>     }
> }
>

 Now this script

>>> import clr
>>> clr.AddReference("System")
<System.Reflection.Assembly object at 0x0435AE50>
>>> from System import *
>>> clr.AddReference("System.Data")
<System.Reflection.Assembly object at 0x0435AE90>
>>> from System.Data import *
>>> clr.AddReference("System.Xml")
<System.Reflection.Assembly object at 0x044F9B10>
>>> from System.Xml import *
>>> clr.AddReference("MyLib")
<System.Reflection.Assembly object at 0x02A95390>
>>>
>>> import MyLib
>>> from MyLib import *

Ready to go!

>>> testI1 = MyLib.CXDoc("path that does exist")
>>>

Yeah all worked fine!


>>> testI2 = MyLib.CXDoc("path that dosn't exist")
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
System.Exception: Deprecated constructor.
   at MyLib.CXDoc..ctor()

What happened!  Well inside the constructor it hit an file not found
exception of some such.
Can someone explain why it hides that from me and calls the default
constructor and shows me that exception.

This seems like an unintuitive thing to do, and has made debugging a huge
pain.

-Chris
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/pythondotnet/attachments/20091214/5c93f10c/attachment.htm>


More information about the PythonDotNet mailing list