BOOST unusual monitoring library (Robinkin organizes)

xiaoxiao2021-03-06  40

// 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 (& TRANSLATE_MY_EXCEPTION1); THE_MONITOR.REGISTER_EXCEPTION_TRANSLATOR (& Translate_my_exception);

Try {THE_MONITOR.EXECUTE ();} catch (boost :: execution_exception const & ex) {std :: cout << "caught exception: << EX.WHAT () << std :: endl;}

Return 0;}

转载请注明原文地址:https://www.9cbs.com/read-54031.html

New Post(0)