Was ist der Grund für die Entfernung dieser Funktionen? Wie kann ich sie nach dem Upgrade auf C++17 ersetzen?
Code: Select all
// function that throws exception that is not specified
void foo() throw(std::logic_error) {
throw std::runtime_error();
}
// function that throws exceptions, but no are specified
void bar() throw() {
throw std::runtime_error();
}
void handler() {
...
}
int main() {
std::set_unexpected(handler);
...
}
Um ein ähnliches Verhalten zu erreichen, kann std::unexpected_handler durch std ersetzt werden: :terminate_handler. Auf diese Weise wird derselbe Handler für
aufgerufen
Code: Select all
// dynamic exception specification is not valid int C++17, so it is removed
void foo() {
throw std::runtime_error();
}
// throw() is replaced with noexcept
void bar() noexcept {
throw std::terminate_handler();
}
void handler() {
...
}
int main() {
std::terminate_handler(handler);
...
}