我得到了下面的代码:例外。尝试 - catch块
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);
}
如果不创建SetOfObjects的情况下,我试图通过这组我得到了预期的运行时错误进行迭代。
因此,我决定处理该错误,并通过try catch的方式向用户提供相关信息。我的程序仍然在运行期间终止,这与我期望的行为相矛盾:它应该继续工作,因为所有生成的异常被处理。这里有什么问题?
你得到了什么错误?如果它只是终止,它可能与异常无关。您标记为“不适用”的代码似乎是真正问题的原因。 – SingerOfTheFall 2012-08-14 10:25:15
如果'SetOfObjects'为null或未初始化的指针,则行为是未定义的。 – hmjd 2012-08-14 10:27:36
我得到未处理的异常。不适用的代码真的不适用(我已经评论过,没有任何改变) – 2012-08-14 10:27:41