Example #1
0
int
cpp_main( int argc , char *[] )
{ 
    ::boost::execution_monitor ex_mon;

    ex_mon.register_exception_translator<my_exception1>( &translate_my_exception1 );
    ex_mon.register_exception_translator<my_exception2>( &translate_my_exception2 );

    try {
        ex_mon.execute( ::boost::unit_test::callback0<int>( dangerous_call( argc ) ) );
    }
    catch ( boost::execution_exception const& ex ) {
        std::cout << "Caught exception: " << ex.what() << std::endl;
    }

    return 0;
}
Example #2
0
int
cpp_main( int argc , char *[] )
{ 
    ::boost::execution_monitor ex_mon;

    ///////////////////////////////////////////////////////////////

    ex_mon.register_exception_translator<my_exception1>( &translate_my_exception1, "except1" );
    ex_mon.register_exception_translator<my_exception2>( &translate_my_exception2, "except2" );

    try {
        ex_mon.execute( ::boost::unit_test::callback0<int>( dangerous_call( argc ) ) );
        std::cout << "Should reach this line " << __LINE__ << std::endl;
    }
    catch ( boost::execution_exception const& ex ) {
        std::cout << "Caught exception: " << ex.what() << std::endl;
    }

    ///////////////////////////////////////////////////////////////

    ex_mon.erase_exception_translator( "except2" );

    try {
        ex_mon.execute( ::boost::unit_test::callback0<int>( dangerous_call( 5 ) ) );
        std::cout << "Should not reach this line " << __LINE__ << std::endl;
    }
    catch ( boost::execution_exception const& ex ) {
        std::cout << "Caught exception: " << ex.what() << std::endl;
    }

    ///////////////////////////////////////////////////////////////

    ex_mon.erase_exception_translator<my_exception1>();

    try {
        ex_mon.execute( ::boost::unit_test::callback0<int>( dangerous_call( 1 ) ) );
        std::cout << "Should not reach this line " << __LINE__ << std::endl;
    }
    catch ( boost::execution_exception const& ex ) {
        std::cout << "Caught exception: " << ex.what() << std::endl;
    }

    ///////////////////////////////////////////////////////////////

    ex_mon.p_detect_fp_exceptions.value = boost::fpe::BOOST_FPE_DIVBYZERO;
    ex_mon.p_catch_system_errors.value = false;

    try {
        ex_mon.execute( &generate_fpe );
        std::cout << "Should not reach this line " << __LINE__ << std::endl;
    }
    catch ( boost::execution_exception const& ex ) {
        std::cout << "Caught exception: " << ex.what() << std::endl;
    }

    ///////////////////////////////////////////////////////////////

    ex_mon.p_detect_fp_exceptions.value = boost::fpe::BOOST_FPE_ALL;

    try {
        ex_mon.execute( &generate_fpe2 );
        std::cout << "Should not reach this line " << __LINE__ << std::endl;
    }
    catch ( boost::execution_exception const& ex ) {
        std::cout << "Caught exception: " << ex.what() << std::endl;
    }

    try {
        ex_mon.execute( &generate_fpe3 );
        std::cout << "Should not reach this line " << __LINE__ << std::endl;
    }
    catch ( boost::execution_exception const& ex ) {
        std::cout << "Caught exception: " << ex.what() << std::endl;
    }

    ///////////////////////////////////////////////////////////////

    ex_mon.p_detect_fp_exceptions.value = boost::fpe::BOOST_FPE_OFF;
    ex_mon.p_catch_system_errors.value = true;

    try {
        ex_mon.execute( &generate_int_div_0 );
        std::cout << "Should not reach this line " << __LINE__ << std::endl;
    }
    catch ( boost::execution_exception const& ex ) {
        std::cout << "Caught exception: " << ex.what() << std::endl;
    }

    ///////////////////////////////////////////////////////////////

    ex_mon.p_detect_fp_exceptions.value = boost::fpe::BOOST_FPE_OFF;
    ex_mon.p_catch_system_errors.value = true;

    try {
        ex_mon.execute( &generate_sigfault );
        std::cout << "Should not reach this line " << __LINE__ << std::endl;
    }
    catch ( boost::execution_exception const& ex ) {
        std::cout << "Caught exception: " << ex.what() << std::endl;
    }

    return 0;
}