These changes to the NcException class will address two issues:
1: Member function what() returned a const char* to a locally declared string variable. The returned pointer was a dangeling pointer as the string variable will be destructed when the function returns.
2: Construction of string variables can throw exceptions. Using strings as membervariables in NcException could result in the constructor throwing in certain cases.
To avoid the possibility of the NcException constructor throwing, the member variables have been changed to a single string. If an exception is thrown in the construction of the message string it will be caught in the NcException constructor and not propagate further. This will also resolve the first issue as the what() function now returns a const char to a non local string.
Note: I used 'nullptr' in the code which is C++11. If the code should not use C++11 'nullptr' should be replaced by 'NULL'
These changes to the NcException class will address two issues: 1: Member function what() returned a const char* to a locally declared string variable. The returned pointer was a dangeling pointer as the string variable will be destructed when the function returns. 2: Construction of string variables can throw exceptions. Using strings as membervariables in NcException could result in the constructor throwing in certain cases.
To avoid the possibility of the NcException constructor throwing, the member variables have been changed to a single string. If an exception is thrown in the construction of the message string it will be caught in the NcException constructor and not propagate further. This will also resolve the first issue as the what() function now returns a const char to a non local string.
Note: I used 'nullptr' in the code which is C++11. If the code should not use C++11 'nullptr' should be replaced by 'NULL'