8 releases

Uses old Rust 2015

0.1.7 Oct 11, 2018
0.1.6 Oct 5, 2018
0.1.5 Sep 3, 2018
0.1.4 Apr 1, 2018
0.1.0 Jun 20, 2015

#1100 in Rust patterns

Download history 29/week @ 2024-03-10 15/week @ 2024-03-17 4/week @ 2024-03-24 25/week @ 2024-03-31 2/week @ 2024-04-07 2/week @ 2024-04-14 7/week @ 2024-04-21 1/week @ 2024-04-28 1/week @ 2024-05-05 8/week @ 2024-05-19 53/week @ 2024-05-26 23/week @ 2024-06-02 39/week @ 2024-06-09 21/week @ 2024-06-16 48/week @ 2024-06-23

133 downloads per month

MIT license

24KB
383 lines

Throw!

Travis CI status

Efficient, statically-calculated backtraces wrapping any error type.

Documentation: https://docs.rs/throw

Throw does not replace existing error handling systems: instead, it simply provides a throw::Error<E> type which wraps your error and provides additional context.

Throw exports two structs, throw::ErrorPoint and throw::Error. throw::Error stores a single original_error variable which it is created from, and then a list of ErrorPoints which starts out with the original point of creation with throw!(), and is added to every time you propagate the error upwards with up!().

throw!() and up!() provide strictly less functionality than alternative crates such as backtrace, but they come with the advantage of performance. Using compiler-provided macros, these functions embed the line number and filename they're used in into the ErrorPoint they construct, and build the stacktrace piece-by-piece at each point. You additionally won't get irrelevant stacktrace lines above where the error is handled! This may be good or bad, depending on your use case.

Throw also only works if you actually use the macros- which is quite a disadvantage. backtrace is most likely what you want if you don't have a strict performance requirement.

Throw in practice: instead of this:

IO Error: failed to lookup address information: Name or service not known

you'll get this:

Error: IO Error: failed to lookup address information: Name or service not known
    at 79:17 in zaldinar::startup (src/startup.rs)
    at 104:4 in zaldinar::startup (src/startup.rs)
    at 28:17 in zaldinar_irclib (/home/daboross/Projects/Rust/zaldinar/zaldinar-irclib/src/lib.rs)

no_std

throw supports building without std, but it will still depend on alloc and use alloc::Vec. This can be enabled when using nightly rust with default-features = false:

throw = { version = "0.1", default-features = false }

Dependencies

~175KB