zoukankan      html  css  js  c++  java
  • vc++ try catch捕捉异常

    try
        {
            //这里写入一些代码
            int a = 11, b = 0;
            int x;
            if (b == 1)
                throw 1; // 抛出异常。终止以下的代码执行 。
            if (a == 1)
                throw 2; // 再抛出个异常。终止以下的代码执行 。
    
            x = a / b; // b=0. 会产生运算异常。
        }
        catch (int i)
        {
            if (i == 1) // 由 throw 抛出的值 =1
                AfxMessageBox("b=1 is error!" );
            if (i == 2) // 由 throw 抛出的值 =2
                AfxMessageBox( "a=1 is error!");
        }
        catch (...) 
        {
            AfxMessageBox("catched b=0");
        } 

    就是仍然使用C++标准的try{}catch(..){},项目/属性/C++/代码生成/启用C++异常   是/EHa。

    或 在编译命令行中加入 /EHa 的参数。

  • 相关阅读:
    Java的特性和优势
    MyBatis
    SpringBoot简介
    Liunx
    MySql简介与入门
    Volatile
    MySQL简介
    Redis
    Spring IoC
    什么是springboot
  • 原文地址:https://www.cnblogs.com/profession/p/12893514.html
Copyright © 2011-2022 走看看