throw std::exception("msg"); 在 MSVC 可編譯,但在 GCC 4.8.1 報錯:call to 'std::exception::exception(const char [n])'。標準 std::exception 建構函式不接受字串參數。
#include <stdexcept>
// 使用衍生類別
std::logic_error ex("XXX");
throw ex; // 或 throw std::logic_error("XXX");
std::logic_error:邏輯錯誤(domain_error, invalid_argument, length_error, out_of_range)。std::runtime_error:執行期錯誤(range_error, overflow_error, underflow_error)。