File tree Expand file tree Collapse file tree 1 file changed +30
-0
lines changed Expand file tree Collapse file tree 1 file changed +30
-0
lines changed Original file line number Diff line number Diff line change @@ -84,6 +84,20 @@ static mut HOOK: Hook = Hook::Default;
8484/// # Panics
8585///
8686/// Panics if called from a panicking thread.
87+ ///
88+ /// # Examples
89+ ///
90+ /// The following will print "Custom panic hook":
91+ ///
92+ /// ```should_panic
93+ /// use std::panic;
94+ ///
95+ /// panic::set_hook(Box::new(|_| {
96+ /// println!("Custom panic hook");
97+ /// }));
98+ ///
99+ /// panic!("Normal panic");
100+ /// ```
87101#[ stable( feature = "panic_hooks" , since = "1.10.0" ) ]
88102pub fn set_hook ( hook : Box < Fn ( & PanicInfo ) + ' static + Sync + Send > ) {
89103 if thread:: panicking ( ) {
@@ -109,6 +123,22 @@ pub fn set_hook(hook: Box<Fn(&PanicInfo) + 'static + Sync + Send>) {
109123/// # Panics
110124///
111125/// Panics if called from a panicking thread.
126+ ///
127+ /// # Examples
128+ ///
129+ /// The following will print "Normal panic":
130+ ///
131+ /// ```should_panic
132+ /// use std::panic;
133+ ///
134+ /// panic::set_hook(Box::new(|_| {
135+ /// println!("Custom panic hook");
136+ /// }));
137+ ///
138+ /// let _ = panic::take_hook();
139+ ///
140+ /// panic!("Normal panic");
141+ /// ```
112142#[ stable( feature = "panic_hooks" , since = "1.10.0" ) ]
113143pub fn take_hook ( ) -> Box < Fn ( & PanicInfo ) + ' static + Sync + Send > {
114144 if thread:: panicking ( ) {
You can’t perform that action at this time.
0 commit comments