| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
1 parent cd21891 commit c9afb7a
2 files changed
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -40,5 +40,19 @@ public void TestNoError() | |||
| 40 | 40 | var e = new PythonException(); // There is no PyErr to fetch | |
| 41 | 41 | Assert.AreEqual("", e.Message); | |
| 42 | 42 | } | |
| 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 | + } | ||
| 43 | 57 | } | |
| 44 | 58 | } | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -13,6 +13,7 @@ public class PythonException : System.Exception | |||
| 13 | 13 | private IntPtr _pyTB = IntPtr.Zero; | |
| 14 | 14 | private string _tb = ""; | |
| 15 | 15 | private string _message = ""; | |
| 16 | + private string _pythonTypeName = ""; | ||
| 16 | 17 | private bool disposed = false; | |
| 17 | 18 | ||
| 18 | 19 | public PythonException() | |
@@ -33,6 +34,8 @@ public PythonException() | |||
| 33 | 34 | type = pyTypeName.ToString(); | |
| 34 | 35 | } | |
| 35 | 36 | ||
| 37 | + _pythonTypeName = type; | ||
| 38 | + | ||
| 36 | 39 | Runtime.XIncref(_pyValue); | |
| 37 | 40 | using (var pyValue = new PyObject(_pyValue)) | |
| 38 | 41 | { | |
@@ -132,6 +135,13 @@ public override string StackTrace | |||
| 132 | 135 | get { return _tb; } | |
| 133 | 136 | } | |
| 134 | 137 | ||
| 138 | + /// <summary> | ||
| 139 | + /// Python error type name. | ||
| 140 | + /// </summary> | ||
| 141 | + public string PythonTypeName | ||
| 142 | + { | ||
| 143 | + get { return _pythonTypeName; } | ||
| 144 | + } | ||
| 135 | 145 | ||
| 136 | 146 | /// <summary> | |
| 137 | 147 | /// Dispose Method | |
| Back | FazBrowse Home | New Git URL |
0 commit comments