zoukankan      html  css  js  c++  java
  • C++的异常处理

    这提到抛出引用类异常,可是那个指针在try中就被释放了,后面就出现访问错误了,见下面代码:

    #include <cstdio>
    using namespace std;
    
    class Ex {
    private:
        int *id;
    public:
        Ex() {
            id = new int;
        }
        ~Ex() {
            delete id;
            id = NULL;
        }
        int errorId() { return *id; }
    };
    
    void fun() throw (Ex, Ex*) {
        Ex *ee = NULL;
        try {
            Ex ex;
            throw &ex;
        } catch (Ex e) {
            printf("catched Ex %d
    ", e.errorId()); 
        } catch (Ex *e) {
            ee = e;
            printf("catched Ex* %d
    ", e->errorId());
        } catch (...) {
            printf("catched other.
    "); 
        }
        if (ee != NULL) {
            ee->errorId();
            printf("OK
    ");
        }
    }
    
    int main () {
        fun();
    }
  • 相关阅读:
    谷歌机器学习
    Pycharm使用conda安装的环境
    HAN模型理解2
    HAN模型理解1
    RCNN
    深度CNN
    多通道CNN
    TextCNN
    词向量2
    词向量1.md
  • 原文地址:https://www.cnblogs.com/litstrong/p/3323866.html
Copyright © 2011-2022 走看看