C++ Interview Question test-3 question-2
来源:互联网 发布:js date unix时间戳 编辑:程序博客网 时间:2024/04/30 04:29
#include <iostream>#include <stdexcept>class A{public: A(int n) : m_n(n) { std::cout << m_n; } ~A() { std::cout << m_n; }private: int m_n;};int f(int n){ if (1 == n) { throw std::logic_error("0"); } A l(n); return f(n - 1) * n / (n - 1);}int main(){ try { int r = f(3); A a(r); } catch (const std::exception &e) { std::cout << e.what() << std::endl; } return 0;}
答案: 32230
1. 出现异常时,会自动抛出,后面所有的语句都不执行,包括递归(其实这也是一种终止递归的方式), 但是该销毁的对象还是会依次销毁。
2. throw std::logic_error("0");“0”就是 exception.what()的内容
0 0
- C++ Interview Question test-3 question-2
- C++ Interview Question test-3 question-3
- C++ Interview Question test-3 question-1
- C++ Interview Question test-3 question-4
- C++ Interview Question test-3 question-5
- interview question(c)
- VLSI Interview question (2)
- Interview question
- interview question
- interview question
- interview question
- interview-question
- Interview Question Site Link
- C# Interview Question
- Java Interview Question
- C# Interview Question
- A Classical Interview Question
- 阿里巴巴 INTERVIEW question
- Android控制所有播放器的音频切换上下首歌、播放、停止
- 读取文件方法大全
- Delphi编写串口通讯方法(转)
- 时间差计算
- 一个操作系统的实现
- C++ Interview Question test-3 question-2
- AC自动机算法详解
- Android开发:Wifi基础
- JSON数据格式和js操作json总结
- Your content must have a TabHost whose id attribute is 'android.R.id.tabhost' 解决
- 手机免费上网时代已经到来
- objc系列译文(3.1):绘制像素到屏幕
- red hat下命令行乱码的解决方法
- ubuntu apache2下目录结构