jeudi 2 juillet 2020

using functional error handling with winapi and std::expected. Should you call std::terminate after GetLastError?

I would like to write code without throwing exceptions using win32 and std::expected<T,DWORD> returning a std::make_unexpected(GetLastError()) in case of an unexpected result. If we threw an exception instead of returning an unexpected and we did/didn't catch it, the program would terminate automatically. So as a library designer would you advise i implement my own terminate handler (std::set_terminate) and call std::abort after each call to GetLastError() ? i am assuming GetLastError is an irrecoverable error. Think of this in terms of c++ functional programming and win32 error handling.

Aucun commentaire:

Enregistrer un commentaire