Согласно cppreference, std::unexpected_handler устарел в C++11 и удален в C++17. То же самое для связанных функций std::unexpected, std::set_unexpected, std::get_unexpected. Я заметил, что некоторые из них упоминались в вопросе. В чем разница между объявлением функции как __attribute__(nothrow) и `throw()`, но с тех пор, как был задан этот вопрос, многое изменилось.
Каково обоснование удаления этих функций? Как их заменить после обновления до C++17?
// 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);
...
}
Изменить
Чтобы добиться аналогичного поведения, std::unexpected_handler можно заменить на std: :terminate_handler. Таким образом, будет вызван тот же обработчик
// 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);
...
}
Подробнее здесь: https://stackoverflow.com/questions/793 ... ed-handler