Когда компилятор встречает исключение из STL, например std::out_of_range
:
int main(int argc, char *argv[]) {
throw std::out_of_range("There is an exception!");
}
консоль покажет сообщение:
libc++abi.dylib: terminating with uncaught exception of type std::out_of_range: There is an exception!
Итак, я написал класс исключений:
class Exception {
protected:
const char *msg;
public:
Exception(const char *msg) noexcept : msg(msg) {}
Exception(const string &msg) noexcept : msg(msg.c_str()) {}
const char *what() const noexcept {
return this->msg;
}
};
Однако, бросив Exception
, вы не получите никакой информации:
int main(int argc, char *argv[]) {
throw Exception("There is an exception!");
}
Консольное сообщение:
libc++abi.dylib: terminating with uncaught exception of type Exception
Есть ли способ сделать консольное шоу:
libc++abi.dylib: terminating with uncaught exception of type Exception: There is an exception!
Компилятор: Apple LLVM version 9.1.0 (clang-902.0.39.2)