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...
    请按任意键继续. . .
  • 相关阅读:
    golang的server push
    go context学习
    go struct{} 空结构体的特点和作用
    Java基本语法--关键字&标识符
    初识Java
    Dos常用命令
    Markdown进阶教程
    Markdown基础教程
    Navicat Premium15安装与激活
    JDK的安装与环境配置(Windows10)
  • 原文地址:https://www.cnblogs.com/Leo-Forest/p/3365490.html
Copyright © 2011-2022 走看看