10 releases (2 stable)

Uses old Rust 2015

2.0.0 Nov 29, 2017
1.0.0 May 25, 2015
0.0.8 May 10, 2015
0.0.6 Mar 7, 2015
0.0.3 Dec 26, 2014

#2133 in Rust patterns

Download history 659/week @ 2024-03-14 702/week @ 2024-03-21 723/week @ 2024-03-28 643/week @ 2024-04-04 751/week @ 2024-04-11 700/week @ 2024-04-18 668/week @ 2024-04-25 460/week @ 2024-05-02 546/week @ 2024-05-09 585/week @ 2024-05-16 475/week @ 2024-05-23 540/week @ 2024-05-30 595/week @ 2024-06-06 446/week @ 2024-06-13 578/week @ 2024-06-20 502/week @ 2024-06-27

2,225 downloads per month
Used in 8 crates (3 directly)

CC0 license


Build Status Latest version License


Current status

This crate is mostly obsolete. For almost all use cases, you should instead add the following to your Cargo.toml file:

panic = 'abort'

This crate is still passively maintained for those few people who have a use-case which is not served by panic = "abort". If you need support for Rust 1.0.0 or later, use version abort_on_panic 1.x. If you need support for Rust 1.22.1 or later, use abort_on_panic 2.x.

Bug-fix PRs will still be accepted, but no future changes are planned at the current time.

Overview (old docs)

When calling Rust code from C, it's unsafe to call panic!. Doing so may cause unsafe behavior. But when calling user-defined functions, we sometimes need to enforce these rules.

To use this library, add the following to your Cargo.toml file:

abort_on_panic = "*"

You can then automatically abort the process when a panic! occurs in a inconvenient location:

#[phase(plugin, link)] extern crate abort_on_panic;

pub fn main() {
    let result = abort_on_panic!({
    assert_eq!("value", result);

    fn oops() {
        panic!("Uh oh.");


I'm working on a Rust wrapper for the Duktape JavaScript interpreter. In a normal use case, the call stack will look like this:

  1. Rust: Arbitrary application code.
  2. Rust: My library wrapper.
  3. C: The Duktape interpreter.
  4. Rust: My Rust code.
  5. Rust: Arbitrary callbacks into application code.

What happens if (5) calls panic!? According to various Rust developers on IRC, attempting to panic! from inside non-Rust callframes like (3) may result in undefined behavior.

But according the Rust documentation, the only way to catch a panic! is using std::task::try, which spawns an extra thread. There's also rustrt::unwind::try, which cannot be nested twice within a single thread, among other restrictions.

One solution, proposed by Benjamin Herr, is to abort the process if the code in (5) panics. Sure, this is less than ideal, but aborting is better than silently corrupting memory and continuing. So this library goes with abort. Are there better alternatives?

Credits & license

The original idea for this code came from Benjamin Herr. Many thanks!

This code is placed into the public domain under the terms described by the Unlicense.

No runtime deps