Enum UnhandledPanic
#[non_exhaustive]pub enum UnhandledPanic {
Ignore,
ShutdownRuntime,
}
tokio_unstable and crate feature rt only.How the runtime should respond to unhandled panics.
Instances of UnhandledPanic are passed to Builder::unhandled_panic to configure the runtime behavior when a spawned task panics.
See Builder::unhandled_panic for more details.
Variants (Non-exhaustive)
Ignore
The runtime should ignore panics on spawned tasks.
The panic is forwarded to the task’s JoinHandle and all spawned tasks continue running normally.
This is the default behavior.
Examples
use tokio::runtime::{self, UnhandledPanic};
let rt = runtime::Builder::new_current_thread()
.unhandled_panic(UnhandledPanic::Ignore)
.build()
.unwrap();
let task1 = rt.spawn(async { panic!("boom"); });
let task2 = rt.spawn(async {
// This task completes normally
"done"
});
rt.block_on(async {
// The panic on the first task is forwarded to the `JoinHandle`
assert!(task1.await.is_err());
// The second task completes normally
assert!(task2.await.is_ok());
})ShutdownRuntime
The runtime should immediately shutdown if a spawned task panics.
The runtime will immediately shutdown even if the panicked task’s JoinHandle is still available. All further spawned tasks will be immediately dropped and call to Runtime::block_on will panic.
Examples
use tokio::runtime::{self, UnhandledPanic};
let rt = runtime::Builder::new_current_thread()
.unhandled_panic(UnhandledPanic::ShutdownRuntime)
.build()
.unwrap();
rt.spawn(async { panic!("boom"); });
rt.spawn(async {
// This task never completes.
});
rt.block_on(async {
// Do some work
})
Trait Implementations
impl Clone for UnhandledPanic
fn clone(&self) -> UnhandledPanic
fn clone_from(&mut self, source: &Self)
source. Read more
Auto Trait Implementations
impl Freeze for UnhandledPanic
impl RefUnwindSafe for UnhandledPanic
impl Send for UnhandledPanic
impl Sync for UnhandledPanic
impl Unpin for UnhandledPanic
impl UnsafeUnpin for UnhandledPanic
impl UnwindSafe for UnhandledPanic
Blanket Implementations
impl<T> BorrowMut<T> for Twhere T: ?Sized,
fn borrow_mut(&mut self) -> &mut T
impl<T> CloneToUninit for Twhere T: Clone,
unsafe fn clone_to_uninit(&self, dest: *mut u8)
clone_to_uninit)
impl<T> Instrument for T
fn instrument(self, span: Span) -> Instrumented<Self> ⓘ
fn in_current_span(self) -> Instrumented<Self> ⓘ
impl<T> WithSubscriber for T
fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self> ⓘ
fn with_current_subscriber(self) -> WithDispatch<Self> ⓘ
MIT License
Copyright © Tokio Contributors
https://docs.rs/tokio/1.53.1/tokio/runtime/enum.UnhandledPanic.html