Is it possible to use a custom panic handler while using std (replacing panic_abort)?

I'm using the custom test framework feature, since i don't have libtest available for my target. std however is available for my target and some tests might require std. Some tests might be should_panic (I'm not exactly sure yet how I would get that information without TestDesc from libtest, but it should be possible one way or another). Anyway I would like to use a custom panic_handler to check if I was running a should_panic test or not in order to set the exit code.

Since I need to explicitly build panic_abort via build-std, would it be possible to make a custom crate called panic_abort and a custom implementation for __rust_start_panic, or is there some more magic going on behind the scenes?

I'm also a bit confused since the parameter _payload is a usize type. Would that just be a pointer to the PanicInfo type?

I’ve never used it, but std::panic::set_hook looks like it might work for you.

1 Like

Thanks, this looks like exactly what I was looking for!

This topic was automatically closed 90 days after the last reply. We invite you to open a new topic if you have further questions or comments.