최대 1 분 소요

개요

  • current_exception으로 던져지고 캡쳐된 예외 객체를 관리하는 포인터
  • 다른 함수로 전달되거나 다시 throw 가능


예제

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

    using namespace std;

    int main() {
    	exception_ptr ex;

    	try {
    		vector<int>().at(0);
    	} catch (...) {
    		ex = current_exception();
    	}

    	auto func = [](exception_ptr ex) {
    		if (ex) {
    			try {
    				rethrow_exception(ex);
    			} catch (const exception &e) {
    				cout << e.what() << endl;
    			}
    		}
    	};

    	func(ex);

    	return 0;
    }
  • 실행 결과
    vector::_M_range_check: __n (which is 0) >= this->size() (which is 0)