QString str = ui.ll->text();
try
{
if (str == NULL)
{
throw 1;
}
else
{
throw 1.2;
}
}
catch (int & e) //参数的类型要与throw中类型保持一致,才能捕捉到;加上&能捕捉到抛出的值
{
if (e == 1)
{
ui.ll->setText("68 04 00 43 00 00 00");
}
qDebug()<<typeid(e).name(); //typeid的具体用法,可以得到数据或对象的类型,用的时候注意不要忘记后面的.name()
myHelper::ShowMessageBoxError(QStringLiteral("解析内容为空,请输入解析报文!"));
return;
}
catch(double & e)
{
if (e == 1.2)
{
ui.ll->setText("1.2");
}
qDebug()<<typeid(e).name();
}
catch(...) //可以捕捉任何异常
{
ui.ll->setText("...");
}
原文:http://www.cnblogs.com/etwd/p/4878712.html