| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -14,16 +14,19 @@ namespace Python.Runtime | |||
| 14 | 14 | /// </summary> | |
| 15 | 15 | public class PythonException : System.Exception | |
| 16 | 16 | { | |
| 17 | - | ||
| 18 | 17 | public PythonException(PyType type, PyObject? value, PyObject? traceback, | |
| 19 | - Exception? innerException) | ||
| 20 | - : base("An exception has occurred in Python code. See Message property for details.", innerException) | ||
| 18 | + string message, Exception? innerException) | ||
| 19 | + : base(message, innerException) | ||
| 21 | 20 | { | |
| 22 | 21 | Type = type ?? throw new ArgumentNullException(nameof(type)); | |
| 23 | 22 | Value = value; | |
| 24 | 23 | Traceback = traceback; | |
| 25 | 24 | } | |
| 26 | 25 | ||
| 26 | + public PythonException(PyType type, PyObject? value, PyObject? traceback, | ||
| 27 | + Exception? innerException) | ||
| 28 | + : this(type, value, traceback, GetMessage(value, type), innerException) { } | ||
| 29 | + | ||
| 27 | 30 | public PythonException(PyType type, PyObject? value, PyObject? traceback) | |
| 28 | 31 | : this(type, value, traceback, innerException: null) { } | |
| 29 | 32 | ||
@@ -178,7 +181,8 @@ private static Exception FromPyErr(BorrowedReference typeRef, BorrowedReference | |||
| 178 | 181 | ||
| 179 | 182 | private static string GetMessage(PyObject? value, PyType type) | |
| 180 | 183 | { | |
| 181 | - using var _ = new Py.GILState(); | ||
| 184 | + if (type is null) throw new ArgumentNullException(nameof(type)); | ||
| 185 | + | ||
| 182 | 186 | if (value != null && !value.IsNone()) | |
| 183 | 187 | { | |
| 184 | 188 | return value.ToString(); | |
@@ -259,17 +263,6 @@ public override string StackTrace | |||
| 259 | 263 | } | |
| 260 | 264 | } | |
| 261 | 265 | ||
| 262 | - public override string Message | ||
| 263 | - { | ||
| 264 | - get | ||
| 265 | - { | ||
| 266 | - if (!PythonEngine.IsInitialized && Runtime.Py_IsInitialized() == 0) | ||
| 267 | - return "Python error message is unavailable as runtime was shut down"; | ||
| 268 | - | ||
| 269 | - return GetMessage(this.Value, this.Type); | ||
| 270 | - } | ||
| 271 | - } | ||
| 272 | - | ||
| 273 | 266 | public bool IsNormalized | |
| 274 | 267 | { | |
| 275 | 268 | get | |
@@ -355,7 +348,8 @@ public string Format() | |||
| 355 | 348 | } | |
| 356 | 349 | ||
| 357 | 350 | public PythonException Clone() | |
| 358 | - => new PythonException(Type, Value, Traceback, InnerException); | ||
| 351 | + => new PythonException(type: Type, value: Value, traceback: Traceback, | ||
| 352 | + Message, InnerException); | ||
| 359 | 353 | ||
| 360 | 354 | internal bool Is(IntPtr type) | |
| 361 | 355 | { | |
| Back | FazBrowse Home | New Git URL |
0 commit comments