File tree 1 file changed +30
-0
lines changed
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;
84
84
/// # Panics
85
85
///
86
86
/// 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
+ /// ```
87
101
#[ stable( feature = "panic_hooks" , since = "1.10.0" ) ]
88
102
pub fn set_hook ( hook : Box < Fn ( & PanicInfo ) + ' static + Sync + Send > ) {
89
103
if thread:: panicking ( ) {
@@ -109,6 +123,22 @@ pub fn set_hook(hook: Box<Fn(&PanicInfo) + 'static + Sync + Send>) {
109
123
/// # Panics
110
124
///
111
125
/// 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
+ /// ```
112
142
#[ stable( feature = "panic_hooks" , since = "1.10.0" ) ]
113
143
pub fn take_hook ( ) -> Box < Fn ( & PanicInfo ) + ' static + Sync + Send > {
114
144
if thread:: panicking ( ) {
You can’t perform that action at this time.
0 commit comments