Possible Duplicate:
What is the difference between throw and throw with arg of caught exception?
Does catch (…) work on throw; with no object?
这将崩溃:
try
{
if(1)
throw;
}
catch(...)
{
printf("hi");
}
我以为我可以做到,但我想没有。当您不需要任何信息时,正确的投掷方法是什么?
最佳答案
#include <exception>
try
{
if(1)
throw std::exception();
}
catch(...)
{
printf("hi");
}
这可能会更好,具体取决于您要做什么:
class my_exception : public std::exception {};
然后,
try
{
if(1)
throw my_exception();
}
catch(my_exception)
{
printf("hi");
}
关于c++ - C++异常裸掷,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/12132983/