Exception not caught in try catch block

前端 未结 5 909
太阳男子
太阳男子 2021-01-13 13:20

I do a simple throw \"TEST THROW\" and it isn\'t caught in my catch (std::exception& e). Is it because I\'m catching an std::exception& e?

5条回答
  •  萌比男神i
    2021-01-13 13:51

    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.

提交回复
热议问题