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

Function excepthook

crates/vm/src/stdlib/sys.rs:838–869  ·  view source on GitHub ↗
(
        exc_type: PyObjectRef,
        exc_val: PyObjectRef,
        exc_tb: PyObjectRef,
        vm: &VirtualMachine,
    )

Source from the content-addressed store, hash-verified

836 #[pyfunction(name = "__excepthook__")]
837 #[pyfunction]
838 fn excepthook(
839 exc_type: PyObjectRef,
840 exc_val: PyObjectRef,
841 exc_tb: PyObjectRef,
842 vm: &VirtualMachine,
843 ) -> PyResult<()> {
844 let stderr = super::get_stderr(vm)?;
845 match vm.normalize_exception(exc_type.clone(), exc_val.clone(), exc_tb) {
846 Ok(exc) => {
847 // PyErr_Display: try traceback._print_exception_bltin first
848 if let Ok(tb_mod) = vm.import("traceback", 0)
849 && let Ok(print_exc_builtin) = tb_mod.get_attr("_print_exception_bltin", vm)
850 && print_exc_builtin
851 .call((exc.as_object().to_owned(),), vm)
852 .is_ok()
853 {
854 return Ok(());
855 }
856 // Fallback to Rust-level exception printing
857 vm.write_exception(&mut crate::py_io::PyWriter(stderr, vm), &exc)
858 }
859 Err(_) => {
860 let type_name = exc_val.class().name();
861 let msg = format!(
862 "TypeError: print_exception(): Exception expected for value, {type_name} found\n"
863 );
864 use crate::py_io::Write;
865 write!(&mut crate::py_io::PyWriter(stderr, vm), "{msg}")?;
866 Ok(())
867 }
868 }
869 }
870
871 #[pyfunction(name = "__breakpointhook__")]
872 #[pyfunction]

Callers

nothing calls this directly

Calls 12

get_stderrFunction · 0.85
PyWriterClass · 0.85
normalize_exceptionMethod · 0.80
write_exceptionMethod · 0.80
cloneMethod · 0.45
importMethod · 0.45
get_attrMethod · 0.45
callMethod · 0.45
to_ownedMethod · 0.45
as_objectMethod · 0.45
nameMethod · 0.45
classMethod · 0.45

Tested by

no test coverage detected