4545import com .oracle .graal .python .builtins .objects .exception .PBaseException ;
4646import com .oracle .graal .python .builtins .objects .type .LazyPythonClass ;
4747import com .oracle .graal .python .builtins .objects .type .PythonClass ;
48+ import com .oracle .graal .python .nodes .attributes .WriteAttributeToObjectNode ;
4849import com .oracle .graal .python .runtime .PythonContext ;
4950import com .oracle .graal .python .runtime .PythonCore ;
5051import com .oracle .graal .python .runtime .exception .PException ;
6263
6364public abstract class PNodeWithContext extends Node {
6465 @ Child private PythonObjectFactory factory ;
66+ @ Child private WriteAttributeToObjectNode writeCause ;
6567 @ CompilationFinal private ContextReference <PythonContext > contextRef ;
6668
6769 protected final PythonObjectFactory factory () {
@@ -88,6 +90,17 @@ public PException raise(LazyPythonClass exceptionType) {
8890 throw raise (factory ().createBaseException (exceptionType ));
8991 }
9092
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+
91104 public final PException raise (PythonBuiltinClassType type , String format , Object ... arguments ) {
92105 assert format != null ;
93106 throw raise (factory ().createBaseException (type , format , arguments ));
0 commit comments