This repository was archived by the owner on Jul 22, 2023. It is now read-only.
File tree Expand file tree Collapse file tree 2 files changed +24
-0
lines changed
Expand file tree Collapse file tree 2 files changed +24
-0
lines changed Original file line number Diff line number Diff line change @@ -40,5 +40,19 @@ public void TestNoError()
4040 var e = new PythonException ( ) ; // There is no PyErr to fetch
4141 Assert . AreEqual ( "" , e . Message ) ;
4242 }
43+
44+ [ Test ]
45+ public void TestPythonErrorTypeName ( )
46+ {
47+ try
48+ {
49+ var module = PythonEngine . ImportModule ( "really____unknown___module" ) ;
50+ Assert . Fail ( "Unknown module should not be loaded" ) ;
51+ }
52+ catch ( PythonException ex )
53+ {
54+ Assert . AreEqual ( ex . PythonTypeName , "ModuleNotFoundError" ) ;
55+ }
56+ }
4357 }
4458}
Original file line number Diff line number Diff line change @@ -13,6 +13,7 @@ public class PythonException : System.Exception
1313 private IntPtr _pyTB = IntPtr . Zero ;
1414 private string _tb = "" ;
1515 private string _message = "" ;
16+ private string _pythonTypeName = "" ;
1617 private bool disposed = false ;
1718
1819 public PythonException ( )
@@ -33,6 +34,8 @@ public PythonException()
3334 type = pyTypeName . ToString ( ) ;
3435 }
3536
37+ _pythonTypeName = type ;
38+
3639 Runtime . XIncref ( _pyValue ) ;
3740 using ( var pyValue = new PyObject ( _pyValue ) )
3841 {
@@ -132,6 +135,13 @@ public override string StackTrace
132135 get { return _tb ; }
133136 }
134137
138+ /// <summary>
139+ /// Python error type name.
140+ /// </summary>
141+ public string PythonTypeName
142+ {
143+ get { return _pythonTypeName ; }
144+ }
135145
136146 /// <summary>
137147 /// Dispose Method
You can’t perform that action at this time.
0 commit comments