Poco Exception例子

社会主义新天地 提交于 2019-11-26 18:31:07

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...
请按任意键继续. . .

 

转载于:https://www.cnblogs.com/Leo-Forest/p/3365490.html

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!