您的位置:首页 > 编程语言 > C语言/C++

A throw-expression with no operand in C++

2011-05-26 14:35 351 查看
    A throw-expression with no operand re-throws the exception currently being handled. Such an expression should appear only in a catch handler or in a function called from within a catch handler. The re-thrown exception object is the original exception object (not a copy). For example: 

 

try {
throw CSomeOtherException();
}
catch(...) {  // Handle all exceptions
// Respond (perhaps only partially) to exception
// ...
throw;       // Pass exception to some other handler
}
[/code]
 

 

 

   An empty throw statement tells the compiler that the function does not throw any exceptions. It is the equivalent to using __declspec(nothrow). For example:

// exceptions_trycatchandthrowstatements3.cpp
void empty() throw()
{
puts("In empty()");
}

void with_type() throw(int)
{
puts("Will throw an int");
throw(1);
}

int main()
{
try {
empty();
with_type();
}catch (int){
puts("Caught an int");
}
}
[/code]
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息