@@ -195,12 +195,7 @@ private AbstractTruffleException handlePythonException(AbstractTruffleException
195
195
if (PythonOptions .isPExceptionWithJavaStacktrace (getPythonLanguage ()) && e instanceof PException pe ) {
196
196
ExceptionUtils .printJavaStackTrace (pe );
197
197
}
198
- if (!getSourceSection ().getSource ().isInteractive ()) {
199
- if (getContext ().isChildContext ()) {
200
- getContext ().getChildContextData ().setExitCode (1 );
201
- }
202
- throw new PythonExitException (this , 1 );
203
- }
198
+ exit (1 );
204
199
}
205
200
// Before we leave Python, format the message since outside the context
206
201
if (e instanceof PException pe ) {
@@ -209,6 +204,15 @@ private AbstractTruffleException handlePythonException(AbstractTruffleException
209
204
throw e ;
210
205
}
211
206
207
+ private void exit (int exitCode ) {
208
+ if (!getSourceSection ().getSource ().isInteractive ()) {
209
+ if (getContext ().isChildContext ()) {
210
+ getContext ().getChildContextData ().setExitCode (1 );
211
+ }
212
+ throw new PythonExitException (this , exitCode );
213
+ }
214
+ }
215
+
212
216
private static boolean isSystemExit (PBaseException pythonException ) {
213
217
return IsBuiltinClassProfile .profileClassSlowPath (GetPythonObjectClassNode .executeUncached (pythonException ), SystemExit );
214
218
}
@@ -227,6 +231,7 @@ private void handleJavaException(Throwable e) {
227
231
if (PythonOptions .shouldPrintJavaStacktrace (getPythonLanguage (), e )) {
228
232
e .printStackTrace ();
229
233
}
234
+ exit (1 );
230
235
}
231
236
} catch (UnsupportedMessageException unsupportedMessageException ) {
232
237
throw CompilerDirectives .shouldNotReachHere ();
@@ -250,12 +255,12 @@ private void handleSystemExit(PBaseException pythonException) {
250
255
int exitcode = getExitCode (pythonException );
251
256
throw new PythonExitException (this , exitcode );
252
257
} catch (CannotCastException e ) {
253
- // fall through
254
- }
255
- if (handleAlwaysRunExceptHook (theContext , pythonException )) {
256
- throw new PythonExitException (this , 1 );
258
+ if (handleAlwaysRunExceptHook (theContext , pythonException )) {
259
+ throw new PythonExitException (this , 1 );
260
+ } else {
261
+ throw pythonException .getExceptionForReraise (pythonException .getTraceback ());
262
+ }
257
263
}
258
- throw pythonException .getExceptionForReraise (pythonException .getTraceback ());
259
264
}
260
265
261
266
@ TruffleBoundary
@@ -264,12 +269,12 @@ private Object handleChildContextExit(PBaseException pythonException) throws PEx
264
269
try {
265
270
return getExitCode (pythonException );
266
271
} catch (CannotCastException cce ) {
267
- // fall through
268
- }
269
- if (handleAlwaysRunExceptHook (getContext (), pythonException )) {
270
- return 1 ;
272
+ if (handleAlwaysRunExceptHook (getContext (), pythonException )) {
273
+ return 1 ;
274
+ } else {
275
+ throw pythonException .getExceptionForReraise (pythonException .getTraceback ());
276
+ }
271
277
}
272
- throw pythonException .getExceptionForReraise (pythonException .getTraceback ());
273
278
}
274
279
275
280
private static int getExitCode (PBaseException pythonException ) throws CannotCastException {
0 commit comments