C++ try catch的问题
来源:互联网 发布:一键获取淘宝联盟 编辑:程序博客网 时间:2024/05/19 23:53
问题
之前一直以为C++的try、catch
和C#一样,程序出现异常的话,会自己抛出,但是今天试了一下,发现是需要自己判断是否有异常,如果有异常的话,需要手动throw异常。
代码
#include<iostream>#include<exception>using namespace std;int main(){ cout << "start!" << endl; int a = 1; int b = 0; try { //int c = a / b; throw 2; } catch (...) { cout << "exception!" << endl; } cout << "end!" << endl; system("pause"); return EXIT_SUCCESS;}如果取消两个数相除的那一行的注释,则会直接报异常,而不会进入`catch`。
0 0
- try--catch语句的catch问题
- try......catch......finally的问题
- try-catch-finally的问题
- C++ try catch的问题
- C语言的try and catch机制
- Try throw catch 的一个问题
- try{}catch{}finally{}的逻辑错误问题
- try- catch嵌套使用解决的问题
- try-catch-finally 引发的奇怪问题
- try catch finally 与 return 的问题
- java try-catch以及循环的问题
- java try-catch以及循环的问题
- java中try-catch的性能问题
- try-catch死循环的问题
- try-catch中的return的问题
- 【c#】try...catch...finally
- c++ try catch 问题
- Try......Catch性能问题
- [整理]VC编译程序时出现the source files are both configured to produce the output file....
- codeforces732E Sockets(贪心)
- C++虚函数与纯虚函数
- 重建二叉树
- 关于浮动知识的总结
- C++ try catch的问题
- 716a
- 94. Binary Tree Inorder Traversal
- 10月再见
- 在Ajax中使用get和post所遇到的问题及解决办法
- 【IT】我是计算机系统大师(一)——硬件基本组成
- C# 给线程传递数据
- SQL server replication的三种方式
- Docker终极指南