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.
Asked
Active
Viewed 1,498 times
5

einpoklum
- 118,144
- 57
- 340
- 684

Ralph Tandetzky
- 22,780
- 11
- 73
- 120
-
1It's also been available for five years as [boost.system](http://www.boost.org/doc/libs/release/libs/system/doc/index.html) – Cubbi Sep 30 '13 at 21:51
-
3Chris Kohlhoff (who was involved in designing `system_error`) has a series of blog posts on the subject, starting with http://blog.think-async.com/2010/04/system-error-support-in-c0x-part-1.html – Fraser Oct 01 '13 at 01:33
1 Answers
3
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.

sasha.sochka
- 14,395
- 10
- 44
- 68