There are enough error handling strategies in C++ already. We have exception handling, error return codes and this ERRNO
mess. What role does the system_error
header play here? How do I use the features in there? To me, it just looks randomly put together. I'm using the cppreference site as a reference.
You can throw
and catch
it as a normal exception. It's just a part of std::exception
hierarchy. std::system_error
extends std::runtime_error
which extends std::exception
When should it be used? Typically it's used for converting C-style ERRNO errors to throw&catch handling with encapsulated error-code inside the object. This is heavily used by standard library itself especially in the new libraries working with OS-specific stuff, e.g. in <thread>
library.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With