【发布时间】:2010-12-20 20:09:14
【问题描述】:
// http://www.parashift.com/c++-faq-lite/misc-technical-issues.html
class BadConversion : public std::runtime_error {
public:
BadConversion(std::string const& s)
: std::runtime_error(s)
{ }
};
inline std::string stringify(double x)
{
std::ostringstream o;
if (!(o << x))
throw BadConversion("stringify(double)");
// throw new BadConversion("stringify(double)");
return o.str();
}
[Q1] 当我们在函数中抛出异常时, throw new ClassName() 和 throw ClassName() 有什么区别?
[Q2]哪个更好?
谢谢
【问题讨论】:
标签: c++ exception exception-handling