// Throw Across Other Handler #include #include #include #include using namespace std::chrono; struct EmptyException : public std::exception {}; struct NotRaisedException {}; void unwind_other(unsigned int frames) { if (frames) { try { unwind_other(frames - 1); } catch (NotRaisedException &) { asm volatile ("# catch block (stack)"); } } else { throw (EmptyException){}; } } int main(int argc, char * argv[]) { unsigned int times = 1; unsigned int total_frames = 1; if (1 < argc) { times = strtol(argv[1], nullptr, 10); } if (2 < argc) { total_frames = strtol(argv[2], nullptr, 10); } time_point start_time = steady_clock::now(); for (int count = 0 ; count < times ; ++count) { try { unwind_other(total_frames); } catch (EmptyException &) { asm volatile ("# catch block (base)"); } } time_point end_time = steady_clock::now(); nanoseconds duration = duration_cast(end_time - start_time); std::cout << "Run-Time (ns): " << duration.count() << std::endl; }