std::thread::panicking

Function std::thread::panicking

pub fn panicking() -> bool

Determines whether the current thread is unwinding because of panic.

Examples

use std::thread;

struct SomeStruct;

impl Drop for SomeStruct {
    fn drop(&mut self) {
        if thread::panicking() {
            println!("dropped while unwinding");
        } else {
            println!("dropped while not unwinding");
        }
    }
}

{
    print!("a: ");
    let a = SomeStruct;
}

{
    print!("b: ");
    let b = SomeStruct;
    panic!()
}

© 2010 The Rust Project Developers
Licensed under the Apache License, Version 2.0 or the MIT license, at your option.
https://doc.rust-lang.org/std/thread/fn.panicking.html

在线笔记
App下载
App下载

扫描二维码

下载编程狮App

公众号
微信公众号

编程狮公众号

意见反馈
返回顶部