Join GitHub today
GitHub is home to over 36 million developers working together to host and review code, manage projects, and build software together.Sign up
Build warnings - throw within destructor #1246
There are a few areas where throw is being called within a destructor. I believe the code "does the right thing", but the multitude of compiler warnings hide other errors/warnings that may be problems. These should be examined to see if they are doing the right thing, and to see if it can be modified to prevent warnings.
The two biggest culprits seem to be
Steps To Reproduce
CORE TEAM TASK LIST
added this to New -Awaiting Core Team Evaluation
in Project Backlog
Aug 10, 2018
This was referenced
Aug 13, 2018
Here is a discussion of pros and cons of throwing in a destructor. I believe most would agree that this is a bad idea, and can lead to undefined behavior.
There are a few places within Bitshares where a destructor can throw. The most prominent example is the session destructor of undo_db. I have reduced the number of warnings displayed by moving the implementation of the destructor from the .hpp to the .cpp.
We must decide what is the desired behavior in this case. We are attempting to clean up the allocations of the session, and something bad happened. Currently, terminate() is called, as per the c++ specifications. I believe this to be the desired behavior. But a warning is generated. To avoid the warning, I believe we should remove the throw and explicitly call std::terminate(). I believe the implications are minimal.
An argument could be made that we should never call terminate within a library. But in a way, that is what we are currently doing. Other options are to not throw (bad idea), or do cleanup outside of the destructor i.e. using a public method (an even worse idea IMO).
Another place where a destructor throws is in database_fixture.cpp. This is testing code so not very critical. My suggestion here would be to log the exception, and call BOOST_FAIL to fail the test.
Cleaning these up will help us see other warnings that are sometimes ignored due to these warnings filling our terminals.
Additional ideas are extremely welcomed.
If the undo_db session destructor throws the internal database is left in an undefined state. There is no reasonable way to clean up continue from there. To avoid the immediate exit it could be an option to somehow invalidate the underlying database.
Using BOOST_FAIL in database_fixture sounds good.
Hmmm. The only advantage I see is that the program keeps running, which may not be a good thing. The database is in an unknown state, unless we can accurately determine the cause and successfully remedy the situation. In that case, I would question the need to throw in the first place. But perhaps you have situations in mind that would benefit from such logic. Would you please elaborate?