由买买提看人间百态

boards

本页内容为未名空间相应帖子的节选和存档,一周内的贴子最多显示50字,超过一周显示500字 访问原贴
Programming版 - C++ Q17: throw 2
相关主题
try catch question可执行程序问题
C++: exception: out-of-order execution?VS里debug不work求教!
does this line get executed after exception caught请教c++里函数调用的问题
Stack Overflow怎么办?how to input arguments in visual C++ .NET
问个问题,关于gdb的问C++文件路径的问题
请问一下,用什么语言/库/脚本作GUI比较方便?如何提取一个executable的所有dependency?
C++ questions请教:如何把程序运行结果转给 bash variable ?
java + javascript open local file?Qt Creator
相关话题的讨论汇总
话题: throw话题: c++话题: error话题: invoked话题: foo
进入Programming版参与讨论
1 (共1页)
c**********e
发帖数: 2007
1
#include
class A {
public:
~A() { throw "error"; }
};
void foo() { A a; throw "error"; }
int main()
{
try { foo(); }
catch (const char*) { return 1; }
return 0;
}
What is the result of executing the sample above?
a) The program exits normally with a result code of 0.
b) The program exits normally with a result code of 1.
c) unexpected() is invoked.
d) terminate() is invoked.
e) There is an uncaught exception because "error" is thrown twice and only
caught once.
z****e
发帖数: 2024
2
d
c**********e
发帖数: 2007
3
Not the answer given.

【在 z****e 的大作中提到】
: d
z****e
发帖数: 2024
4
then your answer is wrong.

【在 c**********e 的大作中提到】
: Not the answer given.
c**********e
发帖数: 2007
5
You do not understand what really happens.

【在 z****e 的大作中提到】
: then your answer is wrong.
z****e
发帖数: 2024
6
LOL

【在 c**********e 的大作中提到】
: You do not understand what really happens.
z****e
发帖数: 2024
7
try the following to see what you are.
#include
#include
void SB_question () {
std::cout<<"i'm an SB"< }
class A {
public:
~A() { throw "error"; }
};
void foo() { A a; throw "error"; }
int main()
{
std::set_terminate (SB_question);
try { foo(); }
catch (const char*) { return 1; }
return 0;
}

【在 c**********e 的大作中提到】
: You do not understand what really happens.
r****t
发帖数: 10904
8
太夸张了,这是人写的程序么。
t****t
发帖数: 6806
9
actually i think you do not understand. the "given" answer is from you, or
from the author? if it is from you, i would say you need to improve your c++
knowledge and please be careful not to mislead other readers. if it is from
the author, apparently the questions are outdated or the author himself
need to improve his c++ knowledge.

【在 c**********e 的大作中提到】
: You do not understand what really happens.
t****t
发帖数: 6806
10
actually not to throw from destructor is the usual practice. see effective c
++.

【在 r****t 的大作中提到】
: 太夸张了,这是人写的程序么。
l******e
发帖数: 12192
11
faq lite也有
讲exception基本都要讲

c

【在 t****t 的大作中提到】
: actually not to throw from destructor is the usual practice. see effective c
: ++.

c**********e
发帖数: 2007
12
I apologize to zaoxie. I misread your answer. Your answer is correct.
Thank thrust for the valuable comment.
d) terminate() is invoked.
This is the correct choice. It is a serious programming error to throw from
a destructor if an exception is already causing stack unwinding (C++
Standard 15.2/3). Throwing from a constructor is usually discouraged, but
if it is to be done, then uncaught_exception() should be checked first (C++
Standard 15.5.3/1).

【在 z****e 的大作中提到】
: then your answer is wrong.
c**********e
发帖数: 2007
13
hehe...This is the output:
i'm an SB
Segmentation fault

【在 z****e 的大作中提到】
: try the following to see what you are.
: #include
: #include
: void SB_question () {
: std::cout<<"i'm an SB"<: }
: class A {
: public:
: ~A() { throw "error"; }
: };

1 (共1页)
进入Programming版参与讨论
相关主题
Qt Creator问个问题,关于gdb的
这段代码有什么问题?请问一下,用什么语言/库/脚本作GUI比较方便?
什么时候使用c++ smart pointer?C++ questions
有用matlab、C++给NAO编程的人吗?java + javascript open local file?
try catch question可执行程序问题
C++: exception: out-of-order execution?VS里debug不work求教!
does this line get executed after exception caught请教c++里函数调用的问题
Stack Overflow怎么办?how to input arguments in visual C++ .NET
相关话题的讨论汇总
话题: throw话题: c++话题: error话题: invoked话题: foo