Poco Exception例子

Poco Exception提供的宏挺方便的。。

#include "Poco/Exception.h"

#include <iostream>

POCO_DECLARE_EXCEPTION( , MyException, Poco::Exception )
POCO_DECLARE_EXCEPTION( , MyFatalException, Poco::Exception )


POCO_IMPLEMENT_EXCEPTION( MyException, Poco::Exception, 
    "Something really bad happened..." )
POCO_IMPLEMENT_EXCEPTION( MyFatalException, Poco::Exception, 
    "Something really really bad happened..." )

void reallyBad () 
{
    throw MyException();
}

void reallyReallyBad ()
{
    throw MyFatalException();
}

int main( void )
{
    try {
        reallyBad();
    } catch ( MyException& ex ) {
        std::cout << ex.displayText() << std::endl;
    } catch ( MyFatalException& ex ) {
        std::cout << ex.displayText() << std::endl;
    }

    try {
        reallyReallyBad();
    } catch ( MyException& ex ) {
        std::cout << ex.displayText() << std::endl;
    } catch ( MyFatalException& ex ) {
        std::cout << ex.displayText() << std::endl;
    }
    system( "pause" );
    return 0;
}

 

输出:

Something really bad happened...
Something really really bad happened...
请按任意键继续. . .

 

posted @ 2013-10-12 16:25  Leo Forest  阅读(858)  评论(0编辑  收藏  举报