Reputation: 4602
Say you have the following destructor in a mutex class wrapping up pthread mutex calls:
~mutex()
{
pthread_mutex_destroy(&m_mutex);
}
If this fails (returns non-zero) we can't throw an exception obviously. How best do we deal with this?
Upvotes: 2
Views: 1159
Reputation: 634
You may take a look at boost::threads: if you are building release - return code will not be checked, and if you are build debug version - abort() will be called with error message printed, BOOST_VERIFY is user for this
Upvotes: 1
Reputation: 18972
Write an error message and call abort(). Hard, visible failure is often preferable to continuing blithely on when the impossible appears to have happened.
Upvotes: 2
Reputation: 72539
The fact that it's inside a destructor is irrelevant. The problem is that you cannot recover if destruction fails (except ignoring it). It's always the case, no matter what language you use.
Upvotes: 1
Reputation: 2326
I suggest a run-time assertion. If it fails, you are in posix's land of undefined behavior.
Upvotes: 0
Reputation: 84239
In my opinion, the only sane recourse in such a case is assert(3)
- something went horribly wrong, so somebody has to investigate ...
Upvotes: 0
Reputation: 500873
I don't think there's a lot you can do other than ignore it (possibly logging a message, especially if you get EBUSY
since this could indicate a serious logic error in your program).
Upvotes: 1