Pre-RFC: panic control


It is often desirable to do some action on program failure, e.g. to show a nice GUI dialog box. This can be done through unwinding, but that requires compiling with unwinding support, which is a performance cost when one has 1 logical task per process.

For example, rustc does not really need landing pads (and would prefer to compile itself with -Z no-landing-pads at least for stage1), but also wants to display a styled error message when compilation is aborted, e.g. because of an trait evaluation overflow.

Insufficiently-detailed proposal

Add a struct PanicInfo and an fn set_panic_handler<F: Fn(PanicInfo)+Send>(f: F). Add some methods for PanicInfo to get the panic information.

why does set_panic_handler never return here? what is this closure supposed to do?

This seems related to C++'s notion of “termination” (which corresponds to the cases where we just abort now).

the ! was accidental. this closure is called on panic. I guess this is basically a duplicate of rfc1100.

ah, ok. :slight_smile: makes sense then.

I’d love to have something like this.

This topic was automatically closed 90 days after the last reply. New replies are no longer allowed.