其他语言

本类阅读TOP10

·基于Solaris 开发环境的整体构思
·使用AutoMake轻松生成Makefile
·BCB数据库图像保存技术
·GNU中的Makefile
·射频芯片nRF401天线设计的分析
·iframe 的自适应高度
·BCB之Socket通信
·软件企业如何实施CMM
·入门系列--OpenGL最简单的入门
·WIN95中日志钩子(JournalRecord Hook)的使用

分类导航
VC语言Delphi
VB语言ASP
PerlJava
Script数据库
其他语言游戏开发
文件格式网站制作
软件工程.NET开发
boost 异常监控库 (RobinKin 整理)

作者:未知 来源:月光软件站 加入时间:2005-2-28 月光软件站

//file name  : mon.cpp
#include <boost/test/execution_monitor.hpp>

#include <iostream>

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::endl; 
}

int cpp_main( int argc , char *[] )
{
}

int
main( int argc , char *[] )
{
    dangerous_call_monitor the_monitor( argc );

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

    try {
        the_monitor.execute();
    }
    catch ( boost::execution_exception const& ex ) {
        std::cout << "Caught exception: " << ex.what() << std::endl;
    }

    return 0;
}

// EOF

编译方式 : g++ -o mon -lboost-prt-exec-monitor-gcc mon.cpp




相关文章

相关软件