zoukankan      html  css  js  c++  java
  • 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...
    请按任意键继续. . .
  • 相关阅读:
    uva 11294 Wedding
    uvalive 4452 The Ministers’ Major Mess
    uvalive 3211 Now Or Later
    uvalive 3713 Astronauts
    uvalive 4288 Cat Vs. Dog
    uvalive 3276 The Great Wall Game
    uva 1411 Ants
    uva 11383 Golden Tiger Claw
    uva 11419 SAM I AM
    uvalive 3415 Guardian Of Decency
  • 原文地址:https://www.cnblogs.com/Leo-Forest/p/3365490.html
Copyright © 2011-2022 走看看