小工具知识网

当前位置: 首页 > 行业知识 > C++对C的改进和拓展\异常处理

行业知识

C++对C的改进和拓展\异常处理

2026-11-25 01:39:43 来源:互联网转载

异常

  • ���序中的错误
    • 语法错误
      • 编译错误
      • 链接错误
      • 运行错误
        • 不可预料的逻辑错误
        • 可以预料的运行异常

          异常处理

          • 将异常交给上层函数处理,减轻底层负担,提高程序运行效率

            异常处理步骤

            • try:检查异常
            • throw:抛出异常
            • catch:捕捉异常信息后进行处理

              try和catch >> 上级函数中处理

              ()

              throw >> 可能出现异常的当前函数中处理

              #include #include using namespace std;int pide(int x, int y){if (y == 0)throw y;//分母为0则抛出异常return x / y;}void output(char x, char y,int m,int n){printf("%c/%c= ", x, y);printf("%d\n",pide(m, n));}int main(){int a = 10, b = 5, c = 0;try//检查是否出现异常{output('a', 'b', a, b);output('b', 'a', b, a);output('a', 'c', a, c);output('c', 'a', c, a);}catch (int){cout 

上一篇:kodi怎么做服务器?

下一篇:金蝶服务器怎么拆?