62
62
import com .oracle .graal .python .nodes .call .CallNode ;
63
63
import com .oracle .graal .python .nodes .call .special .LookupAndCallUnaryNode ;
64
64
import com .oracle .graal .python .nodes .object .IsBuiltinClassProfile ;
65
+ import com .oracle .graal .python .nodes .statement .ExceptionHandlingStatementNode ;
65
66
import com .oracle .graal .python .runtime .ExecutionContext .IndirectCalleeContext ;
66
67
import com .oracle .graal .python .runtime .PythonContext ;
67
68
import com .oracle .graal .python .runtime .PythonCore ;
68
69
import com .oracle .graal .python .runtime .PythonOptions ;
69
70
import com .oracle .graal .python .runtime .exception .ExceptionUtils ;
70
71
import com .oracle .graal .python .runtime .exception .PException ;
71
72
import com .oracle .graal .python .runtime .exception .PythonExitException ;
73
+ import com .oracle .graal .python .runtime .object .PythonObjectFactory ;
72
74
import com .oracle .truffle .api .CompilerDirectives ;
73
75
import com .oracle .truffle .api .CompilerDirectives .CompilationFinal ;
74
76
import com .oracle .truffle .api .CompilerDirectives .TruffleBoundary ;
@@ -89,6 +91,7 @@ public class TopLevelExceptionHandler extends RootNode {
89
91
@ Child private LookupAndCallUnaryNode callStrNode = LookupAndCallUnaryNode .create (__STR__ );
90
92
@ Child private CallNode exceptionHookCallNode = CallNode .create ();
91
93
@ Child private GetExceptionTracebackNode getExceptionTracebackNode ;
94
+ @ Child private PythonObjectFactory pythonObjectFactory ;
92
95
93
96
public TopLevelExceptionHandler (PythonLanguage language , RootNode child ) {
94
97
super (language );
@@ -112,6 +115,14 @@ private PythonContext getContext() {
112
115
return context .get ();
113
116
}
114
117
118
+ private PythonObjectFactory factory () {
119
+ if (pythonObjectFactory == null ) {
120
+ CompilerDirectives .transferToInterpreterAndInvalidate ();
121
+ pythonObjectFactory = insert (PythonObjectFactory .create ());
122
+ }
123
+ return pythonObjectFactory ;
124
+ }
125
+
115
126
@ Override
116
127
public Object execute (VirtualFrame frame ) {
117
128
if (exception != null ) {
@@ -129,7 +140,15 @@ public Object execute(VirtualFrame frame) {
129
140
printStackTrace (e );
130
141
}
131
142
return null ;
132
- } catch (Exception | StackOverflowError e ) {
143
+ } catch (StackOverflowError e ) {
144
+ PException pe = ExceptionHandlingStatementNode .createRecursionError (e , factory (), this );
145
+ PBaseException pythonException = pe .getExceptionObject ();
146
+ printExc (frame , pythonException );
147
+ if (getContext ().getOption (PythonOptions .WithJavaStacktrace )) {
148
+ printStackTrace (e );
149
+ }
150
+ return null ;
151
+ } catch (Exception e ) {
133
152
boolean exitException = e instanceof TruffleException && ((TruffleException ) e ).isExit ();
134
153
if (!exitException ) {
135
154
ExceptionUtils .printPythonLikeStackTrace (e );
0 commit comments