# \[Solved\] Stacktrace info from \`panic::set\_hook\`

**URL:** <https://users.rust-lang.org/t/solved-stacktrace-info-from-panic-set-hook/19631>\
**Category:** help\
**Created:** [August 17, 2018, 3:13pm UTC](https://users.rust-lang.org/t/solved-stacktrace-info-from-panic-set-hook/19631 "2018-08-17T15:13:20Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![dodomorandi](https://sea1.discourse-cdn.com/flex019/user_avatar/users.rust-lang.org/dodomorandi/32/7839_2.png) [@dodomorandi](https://users.rust-lang.org/u/dodomorandi)\
**Post date:** [August 17, 2018, 3:13pm UTC](https://users.rust-lang.org/t/solved-stacktrace-info-from-panic-set-hook/19631/1 "2018-08-17T15:13:20Z")

</div>

Is there any way to get the stacktrace when using the `panic::set_hook`?

I am in the unfortunate position I cannot use RUSTC\_BACKTRACE env variable to understand what is causing a `panic`. My initial idea is to use the `panic::set_hook` to handle the situation and retrieve the information in a custom way. However, I just realized that using `PanicInfo` I only get the location of the single line causing the `panic`. And this is mostly useless when this comes from an `unwrap`ping instance.

---

<div class="post-metadata">

**Author:** ![Michael-F-Bryan](https://sea1.discourse-cdn.com/flex019/user_avatar/users.rust-lang.org/michael-f-bryan/32/28749_2.png) [@Michael-F-Bryan](https://users.rust-lang.org/u/Michael-F-Bryan)\
**Post date:** [August 17, 2018, 3:25pm UTC](https://users.rust-lang.org/t/solved-stacktrace-info-from-panic-set-hook/19631/2 "2018-08-17T15:25:22Z")

</div>

Are you looking for the [backtrace](https://crates.io/crates/backtrace) crate? This is essentially what `RUSTC_BACKTRACE` or `failure` would use under the hood, and it gives you a nice programmatic way of creating and inspecting a backtrace.

---

<div class="post-metadata">

**Author:** ![dodomorandi](https://sea1.discourse-cdn.com/flex019/user_avatar/users.rust-lang.org/dodomorandi/32/7839_2.png) [@dodomorandi](https://users.rust-lang.org/u/dodomorandi)\
**Post date:** [August 17, 2018, 3:40pm UTC](https://users.rust-lang.org/t/solved-stacktrace-info-from-panic-set-hook/19631/3 "2018-08-17T15:40:58Z")

</div>

Perfect, thanks!

I was not sure this was the _actual_ crate to do that -- the 0.2 version was suspicious.

---

<div class="post-metadata">

**Author:** ![kinggoesgaming](https://sea1.discourse-cdn.com/flex019/user_avatar/users.rust-lang.org/kinggoesgaming/32/3839_2.png) [@kinggoesgaming](https://users.rust-lang.org/u/kinggoesgaming)\
**Post date:** [August 19, 2018, 2:22pm UTC](https://users.rust-lang.org/t/solved-stacktrace-info-from-panic-set-hook/19631/4 "2018-08-19T14:22:57Z")

</div>

I am curious on what made you think that?

---

<div class="post-metadata">

**Author:** ![dodomorandi](https://sea1.discourse-cdn.com/flex019/user_avatar/users.rust-lang.org/dodomorandi/32/7839_2.png) [@dodomorandi](https://users.rust-lang.org/u/dodomorandi)\
**Post date:** [August 19, 2018, 4:36pm UTC](https://users.rust-lang.org/t/solved-stacktrace-info-from-panic-set-hook/19631/5 "2018-08-19T16:36:43Z")

</div>

If you are asking why I was unsure about that crate, it is just because in a usual situation we have an _integrated_ stacktrace dumping capability, and I (wrongly) expected to be based on a pretty stable API.

If you are asking why I cannot use the default RUST\_BACKTRACE env variable, it is because I am doing something related to DLL injection on Windows (LD\_PRELOAD, I miss you so much...), and I needed to use the `MessageBoxA` to get the cause of a panic.

---

<div class="post-metadata">

**Author:** ![steffahn](https://sea1.discourse-cdn.com/flex019/user_avatar/users.rust-lang.org/steffahn/32/47569_2.png) [@steffahn](https://users.rust-lang.org/u/steffahn)\
**Post date:** [January 12, 2023, 8:54am UTC](https://users.rust-lang.org/t/solved-stacktrace-info-from-panic-set-hook/19631/6 "2023-01-12T08:54:49Z")

</div>


