Questions tagged [std-system-error]

A C++ standard library mechanism for representing the errors thrown by various library functions with error codes (typically libraries interacting with operating system facilities), and for throwing such errors as exceptions.

16 questions
60
votes
1 answer

What causes runtime error message: std::system_error - operation not permitted, including mult-threading?

Update in 2022 C++ 17 & 20 now have built in support for multithreading in the standard library. I would suggest using these rather than using the Linux specific pthread library. Original Question I wrote a program to test threads on 64 bit kubuntu…
FreelanceConsultant
  • 13,167
  • 27
  • 115
  • 225
37
votes
3 answers

categories and standard/system error codes

C++11 introduced the header containing a generic system to handle error codes. An std::error_code is a tuple containing an int, the error code, and a reference to an std::error_category, which defines the error domain and handling of…
moatPylon
  • 2,103
  • 1
  • 15
  • 22
18
votes
1 answer

Understanding the facility in C++11

I am trying to use the system_error facility to handle errors in a library of mine. I am going to briefly discuss the structure of the library in case you find it helpful: The namespace of the library is called commons and under this I have another…
AstrOne
  • 3,569
  • 7
  • 32
  • 54
8
votes
2 answers

What is the standard conforming way to decide what will be returned by what() from a class inherited from std::system_error without duplicating data?

I use a class inherited from std::system_error for error handling and I'd like to control what is returned when what() is called. Reason: the standard (both C++11 and the draft C++1y CD - N3690, § references below are into the latter) does not…
Norbert Bérci
  • 424
  • 1
  • 4
  • 11
6
votes
3 answers

Does std::exception own `what()`?

I'm deriving my own exception, call it MyException, from std::system_error and have overridden what() to calculate and return my message. MyException's initializer list doesn't call the system_error constructor override that takes a message. If I…
Scott Langham
  • 58,735
  • 39
  • 131
  • 204
6
votes
2 answers

C++11 (or Boost) system_error strategy

I'm working on a system which is designed to use the classes called error_code, error_condition, and error_category -- a scheme newly std: in C++11, altho at the moment I'm actually using the Boost implementation. I've read Chris Kholkoff's series…
Mike C
  • 1,224
  • 10
  • 26
5
votes
1 answer

How do I use `std::error_category` and the other stuff that is in the system_error header?

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…
Ralph Tandetzky
  • 22,780
  • 11
  • 73
  • 120
3
votes
2 answers

Using std::system_category() in static class destructor with msvc11

I'm pretty new to C++, but I want to make sure I'm not doing something wrong here before reporting a bug to Microsoft. Here's some sample code: #include using namespace std; class Test { public: ~Test() { throw…
jmacdonagh
  • 3,851
  • 3
  • 18
  • 14
2
votes
1 answer

Should the mutex operation throw a system_error for locking twice?

Here is the code mutex mtx; try{ mtx.lock(); mtx.lock(); }catch(system_error& e){ mtx.unlock(); cout << e.what() << '\n'; cout << e.code() << '\n'; } An output device or resource busy, generic: 16 is expected but never seen. gcc…
Milo Lu
  • 3,176
  • 3
  • 35
  • 46
1
vote
3 answers

std::system::error exception during recursive_directory_iterator | Unicode Translation Exception 1113 in C++

I was working on a bigger project using the recursive_directory_iterator of std::filesystem, when I stumbled upon this seemingly unknown/unfixable error. I simplified the project to the bare minimum to recreate the error. Another questioner found a…
1
vote
3 answers

How can `std::error_category` safely be used in static destructors?

Consider a custom error type written using the LLVM system_category implementation for reference: #include #include struct my_error_category_type : std::error_category { char const* name() const noexcept override {…
Eric
  • 95,302
  • 53
  • 242
  • 374
1
vote
2 answers

Undeterministic std::system_error: what(): Operation not permitted

I am trying to run my program and once in a few runs I get an error: terminate called after throwing an instance of 'std::system_error' what(): Operation not permitted My code is available here: https://github.com/Qabrt/turnstiles gdb…
Camembert
  • 657
  • 7
  • 11
1
vote
0 answers

ios_base::failure has no code()

I tried the code from cppreference.com but it seems e.code() is not there: #include #include // std::make_error_condition, std::ios_errc int main () { std::cin.exceptions (std::ios::failbit|std::ios::badbit); try { …
towi
  • 21,587
  • 28
  • 106
  • 187
0
votes
2 answers

Is std::error_code a good way to issue warnings?

I'm currently using std::error_code to give feedback to the users of my API when something goes wrong. Would it be semantically acceptable to add an std::error_condition of type warning to notify my users that there was a minor issue but that…
ruipacheco
  • 15,025
  • 19
  • 82
  • 138
0
votes
0 answers

c++ async sometimes resulting in std::system_error , and sometimes not

I am trying to get the code example from there to work: https://solarianprogrammer.com/2012/10/17/cpp-11-async-tutorial/ int twice(int m){ return 2*m; } int main(){ std::vector< std::future > futures; for(int i=0;i<10;++i){ …
Vince
  • 3,979
  • 10
  • 41
  • 69
1
2