MCPcopy Index your code
hub / github.com/RustPython/RustPython / throw

Method throw

crates/vm/src/coroutine.rs:184–209  ·  view source on GitHub ↗
(
        &self,
        jen: &PyObject,
        exc_type: PyObjectRef,
        exc_val: PyObjectRef,
        exc_tb: PyObjectRef,
        vm: &VirtualMachine,
    )

Source from the content-addressed store, hash-verified

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() {

Callers 2

gen_throwMethod · 0.45

Calls 10

fast_isinstanceMethod · 0.80
normalize_exceptionMethod · 0.80
run_with_contextMethod · 0.80
gen_throwMethod · 0.80
maybe_closeMethod · 0.80
into_iter_returnMethod · 0.80
ErrClass · 0.50
is_noneMethod · 0.45
loadMethod · 0.45
cloneMethod · 0.45

Tested by

no test coverage detected