zoukankan      html  css  js  c++  java
  • 63.C++异常

     1 #include <iostream>
     2 using namespace std;
     3 
     4 //异常与错误不一样,异常一般能正常工作
     5 //错误就是程序无法正常工作,无法编译
     6 //异常让程序在错误的输入,文件不存在,内存异常仍然可以正常工作
     7 
     8 int divv(int a, int b)
     9 {
    10     try
    11     {
    12         if (b == 0)
    13         {
    14             throw 1;//抛出
    15         }
    16         cout << a / b << endl;
    17     }
    18     catch (int code)
    19     {
    20         if (code == 1)
    21         {
    22             cout << "被除数不可以为0" << endl;
    23             return 0;
    24         }
    25     }
    26     return a / b;
    27 }
    28     
    29 
    30 void main()
    31 {
    32     cout << divv(100, 0) << endl;
    33     cin.get();
    34 }
  • 相关阅读:
    iOS
    iOS
    iOS
    iOS
    iOS
    iOS
    iOS
    iOS
    iOS
    ajax 几种提交方式
  • 原文地址:https://www.cnblogs.com/xiaochi/p/8568275.html
Copyright © 2011-2022 走看看