I'm making a small error handling system and I want to do a fatal error that terminate the program. I have thought of two way to do that:
[[noreturn]] inline void fatal_error1(char const* msg) {
std::terminate();
}
[[noreturn]] inline void fatal_error2(char const* msg) noexcept {
throw std::runtime_error{msg};
}
Is there a reason why using fatal_error2
would not be recommended? The goal of the function is to terminate the program and I even marked it as noreturn, but everyone seems to tell me to not throw in noexcept functions.
I am tempted to use the fatal_error2
because it output what()
in the terminal, whereas I would need to include some output function in that header to print the message in fatal_error1
.