@@ -154,31 +154,36 @@ public string Format()
154
154
{
155
155
string res ;
156
156
IntPtr gs = PythonEngine . AcquireLock ( ) ;
157
- if ( _pyTB != IntPtr . Zero && _pyType != IntPtr . Zero && _pyValue != IntPtr . Zero )
157
+ try
158
158
{
159
- Runtime . XIncref ( _pyType ) ;
160
- Runtime . XIncref ( _pyValue ) ;
161
- Runtime . XIncref ( _pyTB ) ;
162
- using ( PyObject pyType = new PyObject ( _pyType ) )
163
- using ( PyObject pyValue = new PyObject ( _pyValue ) )
164
- using ( PyObject pyTB = new PyObject ( _pyTB ) )
165
- using ( PyObject tb_mod = PythonEngine . ImportModule ( "traceback" ) )
159
+ if ( _pyTB != IntPtr . Zero && _pyType != IntPtr . Zero && _pyValue != IntPtr . Zero )
166
160
{
8000
code>
167
- var buffer = new StringBuilder ( ) ;
168
- var values = tb_mod . InvokeMethod ( "format_exception" , pyType , pyValue , pyTB ) ;
169
- Runtime . PyErr_Clear ( ) ;
170
- foreach ( PyObject val in values )
161
+ Runtime . XIncref ( _pyType ) ;
162
+ Runtime . XIncref ( _pyValue ) ;
163
+ Runtime . XIncref ( _pyTB ) ;
164
+ using ( PyObject pyType = new PyObject ( _pyType ) )
165
+ using ( PyObject pyValue = new PyObject ( _pyValue ) )
166
+ using ( PyObject pyTB = new PyObject ( _pyTB ) )
167
+ using ( PyObject tb_mod = PythonEngine . ImportModule ( "traceback" ) )
171
168
{
172
- buffer . Append ( val . ToString ( ) ) ;
169
+ var buffer = new StringBuilder ( ) ;
170
+ var values = tb_mod . InvokeMethod ( "format_exception" , pyType , pyValue , pyTB ) ;
171
+ foreach ( PyObject val in values )
172
+ {
173
+ buffer . Append ( val . ToString ( ) ) ;
174
+ }
175
+ res = buffer . ToString ( ) ;
173
176
}
174
- res = buffer . ToString ( ) ;
177
+ }
178
+ else
179
+ {
180
+ res = StackTrace ;
175
181
}
176
182
}
177
- else
183
+ finally
178
184
{
179
- res = "Missing exception/traceback information" ;
185
+ PythonEngine . ReleaseLock ( gs ) ;
180
186
}
181
- PythonEngine . ReleaseLock ( gs ) ;
182
187
return res ;
183
188
}
184
189
0 commit comments