(
exc_type: PyObjectRef,
exc_val: PyObjectRef,
exc_tb: PyObjectRef,
vm: &VirtualMachine,
)
| 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] |
nothing calls this directly
no test coverage detected