diff options
| author | Corey Farwell <coreyf@rwell.org> | 2016-09-10 17:09:02 -0400 |
|---|---|---|
| committer | Corey Farwell <coreyf@rwell.org> | 2016-09-18 10:03:34 -0400 |
| commit | 5505ebc31d1d2e0bddbed815ad0c899c0d42585e (patch) | |
| tree | 003d0e213940396581dad23fc875ddac59df8578 /src/libstd | |
| parent | 141012dd523e6c13924e7c092e1f7f1407430e8c (diff) | |
| download | rust-5505ebc31d1d2e0bddbed815ad0c899c0d42585e.tar.gz rust-5505ebc31d1d2e0bddbed815ad0c899c0d42585e.zip | |
Add basic doc examples for `std::panic::{set_hook, take_hook}`.
Diffstat (limited to 'src/libstd')
| -rw-r--r-- | src/libstd/panicking.rs | 30 |
1 files changed, 30 insertions, 0 deletions
diff --git a/src/libstd/panicking.rs b/src/libstd/panicking.rs index 0c10dcbdad6..1f5b3437b61 100644 --- a/src/libstd/panicking.rs +++ b/src/libstd/panicking.rs @@ -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() { @@ -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() { |
