Does Poco::Exception throw in the copy constructor?

Please post support and help requests here.
Posts: 2
Joined: 08 Oct 2012, 12:25

Does Poco::Exception throw in the copy constructor?

Postby lskywalker » 08 Oct 2012, 16:44

I was looking at the Exception source code, and found that it stores the message as a string member in the exception class. This behavior can result in termination of the program according to the C++ standard (15.5.1), since std::string does not guarantee a non-throwing copy constructor. I found a lot of instances in forums and on stackoverflow where this was said to be bad behavior, see e.g. the discussion in

Is this a deliberate decision in Poco? If so, why? std::runtime_error takes care of this problem by using a shared pointer to the string (at least in clang's libc++).

Posts: 1198
Joined: 11 Jul 2006, 16:27
Location: Austria

Re: Does Poco::Exception throw in the copy constructor?

Postby guenter » 09 Oct 2012, 09:44

IMO, in practice, the probability of this (the std::string copy constructor throwing due to lack of memory while a thrown exception object is being copied) happening is small enough to not worry about it as a first priority. This could be fixed by storing the string and exception pointer in a RefCountedObject. However, if such a situation happens, all bets are off for most applications anyway.

Return to “Support”

Who is online

Users browsing this forum: No registered users and 4 guests