// file name: Mon.cpp # include
#include
Struct my_exception1 {explicit my_exception1 (int res_code): m_res_code (res_code) {}
INT m_RES_CODE;
Struct my_exception2 {explicit my_exception2 (int res_code): m_res_code (res_code) {}
INT m_RES_CODE;
Struct Dangerous_Call_Monitor: Boost :: EXECUTION_MONITOR {Explicit Dangerous_Call_Monitor (int Argc): m_argc (argc) {}
virtual int function () {// here we perform some operation under monitoring that could throw my_exception if (m_argc <2) throw my_exception1 (23); if (m_argc> 3) throw my_exception2 (45); else if (m_argc> 2) Throw "Too Many ARGS";
Return 1;}
INT m_ARGC;
Void translate_my_exception1 (my_exception1 const & ex) {std :: cout << "CAUGHT my_exception1 (" << EX.M_RES_CODE << ")" << std :: endl;}
Void translate_my_exception2 (my_exception2 const & ex) {std :: cout << "caught my_exception2 (" << EX.M_RES_CODE << ")" << std :: end1;
INT CPP_MAIN (int Argc, char * []) {}
INTMAIN (int Argc, char * []) {dangerous_call_monitor the_monitor (argc);
THE_MONITOR.REGISTER_EXCEPTION_TRANSLATOR
Try {THE_MONITOR.EXECUTE ();} catch (boost :: execution_exception const & ex) {std :: cout << "caught exception: << EX.WHAT () << std :: endl;}
Return 0;}