Skip to content

Commit 3effdd3

Browse files
committed
let assert not swallow Java exceptions by default
1 parent 01fb2fb commit 3effdd3

File tree

1 file changed

+8
-2
lines changed
  • graalpython/com.oracle.graal.python/src/com/oracle/graal/python/nodes/statement

1 file changed

+8
-2
lines changed

graalpython/com.oracle.graal.python/src/com/oracle/graal/python/nodes/statement/AssertNode.java

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@ public class AssertNode extends StatementNode {
4343
@Child private ExpressionNode message;
4444
@Child private LookupAndCallUnaryNode callNode;
4545
@CompilationFinal private Boolean assertionsEnabled = null;
46+
@CompilationFinal private boolean javaExceptionsFailAsssertions;
4647

4748
public AssertNode(CastToBooleanNode condition, ExpressionNode message) {
4849
this.condition = condition;
@@ -54,6 +55,7 @@ public void executeVoid(VirtualFrame frame) {
5455
if (assertionsEnabled == null) {
5556
CompilerDirectives.transferToInterpreterAndInvalidate();
5657
assertionsEnabled = !PythonOptions.getOption(getContext(), PythonOptions.PythonOptimizeFlag);
58+
javaExceptionsFailAsssertions = PythonOptions.getOption(getContext(), PythonOptions.CatchAllExceptions);
5759
}
5860
if (assertionsEnabled) {
5961
try {
@@ -64,8 +66,12 @@ public void executeVoid(VirtualFrame frame) {
6466
// Python exceptions just fall through
6567
throw e;
6668
} catch (Exception e) {
67-
// catch any other exception and convert to Python exception
68-
throw assertionFailed(frame);
69+
if (javaExceptionsFailAsssertions) {
70+
// catch any other exception and convert to Python exception
71+
throw assertionFailed(frame);
72+
} else {
73+
throw e;
74+
}
6975
}
7076
}
7177
}

0 commit comments

Comments
 (0)