I got the following code:
set<Object*>::iterator it;
try
{
for (it = SetOfObjects->begin(); it != SetOfObjects->end(); ++it)
{
//some actions, not applicable to the question
}
}
catch(...)
{
this->m_error_raiser->error_Name = "Station isn`t connected to Object! Use connectToObject method or list of forecast objects is empty";
this->m_error_raiser->error_Number = 101;
//throw (this->m_error_raiser);
}
When instance of SetOfObjects is not created and I am trying to iterate through that set I got expected run- time error.
So I decided to handle that error and give info about it to the user by means of try catch.
My question: although I catch all exceptions thus they are considered handled, my program still terminates during run -time which contradicts to it`s behavior which I expect from it: it should continue to work because all generated exceptions were handled. What is wrong here?
If object is pointer and it’s not initialized, usage of such object is
undefined behaviour. You can’t handle usage of such pointer byexception handling(by standard). Only initialize to 0 by default and verify that pointer is notnullbefore usage.