如何使用try catch块避免这种异常? [英] How to avoid this exception using try catch block?

查看:125
本文介绍了如何使用try catch块避免这种异常?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

CString Meal::GetKitchenNote()
{
	try{
		return m_KitchenNote;
	 }
	catch(CString m_KitchenNote )
	{
		return CString("");
	}



我正在使用上面的代码,程序崩溃了,如何避免这种异常.
正在收到此异常:CXX0017:错误:符号"m_KitchenNote?"找不到



I am using the above code, the program crashes, how to avoid this exception..

Am getting this exception: CXX0017: Error: symbol "m_KitchenNote?" not found

推荐答案

这是编译时错误.确保您正确拼写了变量名,并且该变量名存在于Meal的类定义中.

另外,return m_KitchenNote;不会抛出任何异常,因此这里不需要尝试/捕获.
This is a compile time error. Make sure you spelt the variable name correctly and that it exists in the class definition for Meal.

Additionally, return m_KitchenNote; will not throw any exceptions, so there is no need for a try/catch here.


您应该使用:
You should be using :
...
catch(Exception *e)
{
}
...


这篇关于如何使用try catch块避免这种异常?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆