75
75
import com .oracle .truffle .api .CompilerDirectives ;
76
76
import com .oracle .truffle .api .CompilerDirectives .TruffleBoundary ;
77
77
import com .oracle .truffle .api .RootCallTarget ;
78
+ import com .oracle .truffle .api .exception .AbstractTruffleException ;
78
79
import com .oracle .truffle .api .frame .VirtualFrame ;
79
80
import com .oracle .truffle .api .interop .ExceptionType ;
80
81
import com .oracle .truffle .api .interop .InteropLibrary ;
@@ -142,10 +143,9 @@ public Object execute(VirtualFrame frame) {
142
143
assert pythonContext .getThreadState (lang ).getCurrentException () == null ;
143
144
try {
144
145
return run (frame );
145
- } catch (PException e ) {
146
+ } catch (AbstractTruffleException e ) {
146
147
assert !PArguments .isPythonFrame (frame );
147
- Object pythonException = e .getEscapedException ();
148
- if (pythonException instanceof PBaseException managedException && getContext ().isChildContext () && isSystemExit (managedException )) {
148
+ if (e instanceof PException pe && pe .getEscapedException () instanceof PBaseException managedException && getContext ().isChildContext () && isSystemExit (managedException )) {
149
149
return handleChildContextExit (managedException );
150
150
}
151
151
throw handlePythonException (e );
@@ -171,8 +171,8 @@ private void checkInitialized() {
171
171
}
172
172
173
173
@ TruffleBoundary
174
- private PException handlePythonException (PException pException ) {
175
- Object pythonException = pException .getEscapedException ();
174
+ private AbstractTruffleException handlePythonException (AbstractTruffleException e ) {
175
+ Object pythonException = e instanceof PException pe ? pe .getEscapedException () : e ;
176
176
if (pythonException instanceof PBaseException managedException && isSystemExit (managedException )) {
177
177
handleSystemExit (managedException );
178
178
}
@@ -186,8 +186,8 @@ private PException handlePythonException(PException pException) {
186
186
sys .setAttribute (BuiltinNames .T_LAST_TRACEBACK , tb );
187
187
188
188
ExceptionUtils .printExceptionTraceback (getContext (), pythonException );
189
- if (PythonOptions .isPExceptionWithJavaStacktrace (getPythonLanguage ())) {
190
- ExceptionUtils .printJavaStackTrace (pException );
189
+ if (PythonOptions .isPExceptionWithJavaStacktrace (getPythonLanguage ()) && e instanceof PException pe ) {
190
+ ExceptionUtils .printJavaStackTrace (pe );
191
191
}
192
192
if (!getSourceSection ().getSource ().isInteractive ()) {
193
193
if (getContext ().isChildContext ()) {
@@ -197,10 +197,10 @@ private PException handlePythonException(PException pException) {
197
197
}
198
198
}
199
199
// Before we leave Python, format the message since outside the context
200
- if (pythonException instanceof PBaseException managedException ) {
201
- pException .setMessage (managedException .getFormattedMessage ());
200
+ if (e instanceof PException pe && pythonException instanceof PBaseException managedException ) {
201
+ pe .setMessage (managedException .getFormattedMessage ());
202
202
}
203
- throw pException ;
203
+ throw e ;
204
204
}
205
205
206
206
private static boolean isSystemExit (PBaseException pythonException ) {
0 commit comments