최대 1 분 소요

개요

  • uncaught_exception
    • C++11
    • 현재 스레드에서 스택 해제가 진행 중이면 true, 아니면 false
  • uncaught_exceptions
    • C++17
    • 현재 스레드에서 catch되지 않은 exception의 수


예제

  • 코드
    #include <exception>
    #include <iostream>

    using namespace std;

    class Test {
    	private:
    		int i;

    	public:
    		Test(int i) : i(i){};
    		~Test() {
    			cout << this->i << " : " << uncaught_exception() << endl;
    			cout << this->i << " : " << uncaught_exceptions() << endl;
    		}
    };

    int main() {
    	Test t1(1);

    	try {
    		Test t2(2);

    		throw runtime_error("runtime_error");
    	} catch (const exception &e) {
    		cout << e.what() << endl;
    	}

    	Test t3(3);

    	return 0;
    }
  • 실행 결과
    2 : 1
    2 : 1
    runtime_error
    3 : 0
    3 : 0
    1 : 0
    1 : 0