且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

异常未捕获在try catch块中

更新时间:2023-02-06 13:11:19

您正在抛出 const char * std :: exception 仅捕获 std :: exception 及其所有派生类。因此,为了赶上您的投掷,您应该投掷 std :: runtime_error( TEST THROW)。或 std :: logic_error( TEST THROW);任何合适的选择。 std :: exception 的派生类为在这里列出

You're throwing a const char*. std::exception only catches std::exception and all derived classes of it. So in order to catch your throw, you should throw std::runtime_error("TEST THROW") instead. Or std::logic_error("TEST THROW"); whatever fits better. The derived classes of std::exception are listed here.