Skip to content

Commit 9110f26

Browse files
committed
add isException/throwException messages
1 parent e335348 commit 9110f26

File tree

1 file changed

+32
-1
lines changed
  • graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/exception

1 file changed

+32
-1
lines changed

graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/exception/PBaseException.java

Lines changed: 32 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,12 +40,14 @@
4040
*/
4141
package com.oracle.graal.python.builtins.objects.exception;
4242

43+
import com.oracle.graal.python.builtins.objects.PNone;
4344
import com.oracle.graal.python.builtins.objects.frame.PFrame;
4445
import com.oracle.graal.python.builtins.objects.object.PythonObject;
4546
import com.oracle.graal.python.builtins.objects.traceback.PTraceback;
4647
import com.oracle.graal.python.builtins.objects.tuple.PTuple;
4748
import com.oracle.graal.python.builtins.objects.type.LazyPythonClass;
4849
import com.oracle.graal.python.builtins.objects.type.TypeNodes.GetNameNode;
50+
import com.oracle.graal.python.nodes.PRaiseNode;
4951
import com.oracle.graal.python.nodes.object.GetLazyClassNode;
5052
import com.oracle.graal.python.nodes.statement.ExceptNode;
5153
import com.oracle.graal.python.runtime.exception.PException;
@@ -54,9 +56,12 @@
5456
import com.oracle.graal.python.runtime.sequence.storage.BasicSequenceStorage;
5557
import com.oracle.graal.python.runtime.sequence.storage.SequenceStorage;
5658
import com.oracle.truffle.api.CompilerAsserts;
59+
import com.oracle.truffle.api.dsl.Cached;
60+
import com.oracle.truffle.api.library.ExportMessage;
61+
import com.oracle.truffle.api.profiles.ConditionProfile;
5762

5863
public final class PBaseException extends PythonObject {
59-
64+
private static final Object[] EMPTY_ARGS = new Object[0];
6065
private static final ErrorMessageFormatter FORMATTER = new ErrorMessageFormatter();
6166

6267
private PTuple args; // can be null for lazily generated message
@@ -225,4 +230,30 @@ public void reifyException(PFrame.Reference curFrameInfo) {
225230
// TODO: frames: provide legacy stack walk method via Python option
226231
// TruffleStackTrace.fillIn(exception);
227232
}
233+
234+
@ExportMessage
235+
@SuppressWarnings("static-method")
236+
boolean isException() {
237+
return true;
238+
}
239+
240+
@ExportMessage
241+
RuntimeException throwException(@Cached("createBinaryProfile()") ConditionProfile hasExc,
242+
@Cached GetLazyClassNode getClass,
243+
@Cached PRaiseNode raiseNode) {
244+
PException exc = getException();
245+
if (hasExc.profile(exc != null)) {
246+
throw exc;
247+
} else {
248+
Object[] newArgs = messageArgs;
249+
if (newArgs == null) {
250+
newArgs = EMPTY_ARGS;
251+
}
252+
Object format = messageFormat;
253+
if (format == null) {
254+
format = PNone.NO_VALUE;
255+
}
256+
throw raiseNode.execute(getClass.execute(this), this, format, newArgs);
257+
}
258+
}
228259
}

0 commit comments

Comments
 (0)