45
45
import com .oracle .graal .python .builtins .objects .exception .PBaseException ;
46
46
import com .oracle .graal .python .builtins .objects .type .LazyPythonClass ;
47
47
import com .oracle .graal .python .builtins .objects .type .PythonClass ;
48
+ import com .oracle .graal .python .nodes .attributes .WriteAttributeToObjectNode ;
48
49
import com .oracle .graal .python .runtime .PythonContext ;
49
50
import com .oracle .graal .python .runtime .PythonCore ;
50
51
import com .oracle .graal .python .runtime .exception .PException ;
62
63
63
64
public abstract class PNodeWithContext extends Node {
64
65
@ Child private PythonObjectFactory factory ;
66
+ @ Child private WriteAttributeToObjectNode writeCause ;
65
67
@ CompilationFinal private ContextReference <PythonContext > contextRef ;
66
68
67
69
protected final PythonObjectFactory factory () {
@@ -88,6 +90,17 @@ public PException raise(LazyPythonClass exceptionType) {
88
90
throw raise (factory ().createBaseException (exceptionType ));
89
91
}
90
92
93
+ public final PException raise (PythonBuiltinClassType type , PBaseException cause , String format , Object ... arguments ) {
94
+ assert format != null ;
95
+ PBaseException baseException = factory ().createBaseException (type , format , arguments );
96
+ if (writeCause == null ) {
97
+ CompilerDirectives .transferToInterpreterAndInvalidate ();
98
+ writeCause = insert (WriteAttributeToObjectNode .create ());
99
+ }
100
+ writeCause .execute (baseException , SpecialAttributeNames .__CAUSE__ , cause );
101
+ throw raise (baseException );
102
+ }
103
+
91
104
public final PException raise (PythonBuiltinClassType type , String format , Object ... arguments ) {
92
105
assert format != null ;
93
106
throw raise (factory ().createBaseException (type , format , arguments ));
0 commit comments