(
&self,
jen: &PyObject,
exc_type: PyObjectRef,
exc_val: PyObjectRef,
exc_tb: PyObjectRef,
vm: &VirtualMachine,
)
| 182 | } |
| 183 | |
| 184 | pub fn throw( |
| 185 | &self, |
| 186 | jen: &PyObject, |
| 187 | exc_type: PyObjectRef, |
| 188 | exc_val: PyObjectRef, |
| 189 | exc_tb: PyObjectRef, |
| 190 | vm: &VirtualMachine, |
| 191 | ) -> PyResult<PyIterReturn> { |
| 192 | // Validate throw arguments (_gen_throw) |
| 193 | if exc_type.fast_isinstance(vm.ctx.exceptions.base_exception_type) && !vm.is_none(&exc_val) |
| 194 | { |
| 195 | return Err(vm.new_type_error("instance exception may not have a separate value")); |
| 196 | } |
| 197 | if !vm.is_none(&exc_tb) && !exc_tb.fast_isinstance(vm.ctx.types.traceback_type) { |
| 198 | return Err(vm.new_type_error("throw() third argument must be a traceback object")); |
| 199 | } |
| 200 | if self.closed.load() { |
| 201 | return Err(vm.normalize_exception(exc_type, exc_val, exc_tb)?); |
| 202 | } |
| 203 | // Validate exception type before entering generator context. |
| 204 | // Invalid types propagate to caller without closing the generator. |
| 205 | crate::exceptions::ExceptionCtor::try_from_object(vm, exc_type.clone())?; |
| 206 | let result = self.run_with_context(jen, vm, |f| f.gen_throw(vm, exc_type, exc_val, exc_tb)); |
| 207 | self.maybe_close(&result); |
| 208 | Ok(result?.into_iter_return(vm)) |
| 209 | } |
| 210 | |
| 211 | pub fn close(&self, jen: &PyObject, vm: &VirtualMachine) -> PyResult<PyObjectRef> { |
| 212 | if self.closed.load() { |
no test coverage detected