1
1
/*
2
- * Copyright (c) 2017, 2019 , Oracle and/or its affiliates.
2
+ * Copyright (c) 2017, 2020 , Oracle and/or its affiliates.
3
3
* Copyright (c) 2013, Regents of the University of California
4
4
*
5
5
* All rights reserved.
30
30
import com .oracle .graal .python .nodes .util .ExceptionStateNodes .SaveExceptionStateNode ;
31
31
import com .oracle .graal .python .nodes .util .ExceptionStateNodes .SetCaughtExceptionNode ;
32
32
import com .oracle .graal .python .runtime .exception .PException ;
33
+ import com .oracle .truffle .api .CompilerAsserts ;
33
34
import com .oracle .truffle .api .CompilerDirectives ;
34
35
import com .oracle .truffle .api .frame .VirtualFrame ;
35
36
import com .oracle .truffle .api .nodes .ControlFlowException ;
@@ -56,19 +57,30 @@ public void executeVoid(VirtualFrame frame) {
56
57
restoreExceptionState (frame , exceptionState );
57
58
}
58
59
} else {
60
+ boolean executeFinalbody = true ;
59
61
try {
60
62
body .executeVoid (frame );
61
63
} catch (PException e ) {
62
64
// any thrown Python exception is visible in the finally block
63
65
SetCaughtExceptionNode .execute (frame , e );
64
66
throw e ;
67
+ } catch (ControlFlowException e ) {
68
+ throw e ;
69
+ } catch (Throwable e ) {
70
+ // Don't execute finally block on exceptions that occured in the interpreter itself
71
+ CompilerDirectives .transferToInterpreter ();
72
+ executeFinalbody = false ;
73
+ throw e ;
65
74
} finally {
66
- try {
67
- finalbody .executeVoid (frame );
68
- } catch (ControlFlowException e ) {
69
- // restore
70
- restoreExceptionState (frame , exceptionState );
71
- throw e ;
75
+ CompilerAsserts .partialEvaluationConstant (executeFinalbody );
76
+ if (executeFinalbody ) {
77
+ try {
78
+ finalbody .executeVoid (frame );
79
+ } catch (ControlFlowException e ) {
80
+ // restore
81
+ restoreExceptionState (frame , exceptionState );
82
+ throw e ;
83
+ }
72
84
}
73
85
// restore
74
86
restoreExceptionState (frame , exceptionState );
0 commit comments