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

Method print_exception

crates/vm/src/exceptions.rs:55–77  ·  view source on GitHub ↗

Print exception chain by calling sys.excepthook

(&self, exc: PyBaseExceptionRef)

Source from the content-addressed store, hash-verified

53
54 /// Print exception chain by calling sys.excepthook
55 pub fn print_exception(&self, exc: PyBaseExceptionRef) {
56 let vm = self;
57 let write_fallback = |exc, errstr| {
58 if let Ok(stderr) = sys::get_stderr(vm) {
59 let mut stderr = py_io::PyWriter(stderr, vm);
60 // if this fails stderr might be closed -- ignore it
61 let _ = writeln!(stderr, "{errstr}");
62 let _ = self.write_exception(&mut stderr, exc);
63 } else {
64 eprintln!("{errstr}\nlost sys.stderr");
65 let _ = self.write_exception(&mut py_io::IoWriter(io::stderr()), exc);
66 }
67 };
68 if let Ok(excepthook) = vm.sys_module.get_attr("excepthook", vm) {
69 let (exc_type, exc_val, exc_tb) = vm.split_exception(exc.clone());
70 if let Err(eh_exc) = excepthook.call((exc_type, exc_val, exc_tb), vm) {
71 write_fallback(&eh_exc, "Error in sys.excepthook:");
72 write_fallback(&exc, "Original exception was:");
73 }
74 } else {
75 write_fallback(&exc, "missing sys.excepthook");
76 }
77 }
78
79 pub fn write_exception<W: Write>(
80 &self,

Calls 8

get_stderrFunction · 0.85
PyWriterClass · 0.85
IoWriterClass · 0.85
write_exceptionMethod · 0.80
split_exceptionMethod · 0.80
get_attrMethod · 0.45
cloneMethod · 0.45
callMethod · 0.45