|
41 | 41 | package com.oracle.graal.python.nodes.statement;
|
42 | 42 |
|
43 | 43 | import static com.oracle.graal.python.builtins.PythonBuiltinClassType.RecursionError;
|
| 44 | +import static com.oracle.graal.python.runtime.exception.PythonErrorType.SystemError; |
44 | 45 |
|
45 | 46 | import com.oracle.graal.python.PythonLanguage;
|
46 | 47 | import com.oracle.graal.python.builtins.objects.exception.PBaseException;
|
|
49 | 50 | import com.oracle.graal.python.runtime.PythonContext;
|
50 | 51 | import com.oracle.graal.python.runtime.PythonOptions;
|
51 | 52 | import com.oracle.graal.python.runtime.exception.PException;
|
52 |
| -import com.oracle.graal.python.runtime.exception.PythonErrorType; |
53 | 53 | import com.oracle.graal.python.runtime.object.PythonObjectFactory;
|
54 | 54 | import com.oracle.truffle.api.CompilerDirectives;
|
55 | 55 | import com.oracle.truffle.api.CompilerDirectives.CompilationFinal;
|
@@ -187,41 +187,31 @@ protected boolean shouldCatchAllExceptions() {
|
187 | 187 | return shouldCatchAllExceptions;
|
188 | 188 | }
|
189 | 189 |
|
190 |
| - private PException wrapJavaException(Throwable e) { |
191 |
| - PException pe = PException.fromObject(getBaseException(e), this); |
| 190 | + public static PException wrapJavaException(Throwable e, Node node, PBaseException pythonException) { |
| 191 | + PException pe = PException.fromObject(pythonException, node); |
192 | 192 | pe.setHideLocation(true);
|
193 | 193 | // Re-attach truffle stacktrace
|
194 | 194 | moveTruffleStackTrace(e, pe);
|
195 |
| - return pe; |
| 195 | + // Create a new traceback chain, because the current one has been finalized by Truffle |
| 196 | + return pe.getExceptionForReraise(); |
196 | 197 | }
|
197 | 198 |
|
| 199 | + @TruffleBoundary |
198 | 200 | protected PException wrapJavaExceptionIfApplicable(Throwable e) {
|
199 | 201 | if (e instanceof StackOverflowError) {
|
200 |
| - return createRecursionError(e, factory(), this); |
| 202 | + return wrapJavaException(e, this, factory().createBaseException(RecursionError, "maximum recursion depth exceeded", new Object[]{})); |
201 | 203 | }
|
202 | 204 | if (shouldCatchAllExceptions() && (e instanceof Exception || e instanceof AssertionError)) {
|
203 |
| - return wrapJavaException(e); |
| 205 | + return wrapJavaException(e, this, factory().createBaseException(SystemError, "%m", new Object[]{e})); |
204 | 206 | }
|
205 | 207 | return null;
|
206 | 208 | }
|
207 | 209 |
|
208 |
| - public static PException createRecursionError(Throwable e, PythonObjectFactory factory, Node location) { |
209 |
| - PException pe = PException.fromObject(factory.createBaseException(RecursionError, "maximum recursion depth exceeded", new Object[]{}), location); |
210 |
| - pe.setHideLocation(true); |
211 |
| - moveTruffleStackTrace(e, pe); |
212 |
| - return pe; |
213 |
| - } |
214 |
| - |
215 | 210 | @TruffleBoundary
|
216 | 211 | private static void moveTruffleStackTrace(Throwable e, PException pe) {
|
217 | 212 | pe.initCause(e.getCause());
|
218 | 213 | // Host exceptions have their stacktrace already filled in, call this to set
|
219 | 214 | // the cutoff point to the catch site
|
220 | 215 | pe.getTruffleStackTrace();
|
221 | 216 | }
|
222 |
| - |
223 |
| - @TruffleBoundary |
224 |
| - private PBaseException getBaseException(Throwable e) { |
225 |
| - return factory().createBaseException(PythonErrorType.SystemError, "%m", new Object[]{e}); |
226 |
| - } |
227 | 217 | }
|
0 commit comments