Skip to content

Commit

Permalink
Auto merge of #36390 - frewsxcv:panic-set-hook, r=GuillaumeGomez
Browse files Browse the repository at this point in the history
Add basic doc examples for `std::panic::{set_hook, take_hook}`.

None
  • Loading branch information
bors committed Sep 18, 2016
2 parents 22d15ea + 5505ebc commit 3392775
Showing 1 changed file with 30 additions and 0 deletions.
30 changes: 30 additions & 0 deletions src/libstd/panicking.rs
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,20 @@ static mut HOOK: Hook = Hook::Default;
/// # Panics
///
/// Panics if called from a panicking thread.
///
/// # Examples
///
/// The following will print "Custom panic hook":
///
/// ```should_panic
/// use std::panic;
///
/// panic::set_hook(Box::new(|_| {
/// println!("Custom panic hook");
/// }));
///
/// panic!("Normal panic");
/// ```
#[stable(feature = "panic_hooks", since = "1.10.0")]
pub fn set_hook(hook: Box<Fn(&PanicInfo) + 'static + Sync + Send>) {
if thread::panicking() {
Expand All @@ -109,6 +123,22 @@ pub fn set_hook(hook: Box<Fn(&PanicInfo) + 'static + Sync + Send>) {
/// # Panics
///
/// Panics if called from a panicking thread.
///
/// # Examples
///
/// The following will print "Normal panic":
///
/// ```should_panic
/// use std::panic;
///
/// panic::set_hook(Box::new(|_| {
/// println!("Custom panic hook");
/// }));
///
/// let _ = panic::take_hook();
///
/// panic!("Normal panic");
/// ```
#[stable(feature = "panic_hooks", since = "1.10.0")]
pub fn take_hook() -> Box<Fn(&PanicInfo) + 'static + Sync + Send> {
if thread::panicking() {
Expand Down

0 comments on commit 3392775

Please sign in to comment.