示意代码如下(信手写的,没测试): int fun(int m,int n) { int l; if(n==0) throw "I'm called! A exception is throwed in fun()!"; l=m/n; return l; } try { int a=rand(),b=rand(),c; c=fun(a,b); AfxMessageBox("Call me! No Exception is throwed in fun()"); } catch(char* errMes) { AfxMessageBox(errMes); }
不是错误
int fun(int m,int n)
{
int l;
if(n==0)
throw "I'm called! A exception is throwed in fun()!";
l=m/n;
return l;
}
try
{
int a=rand(),b=rand(),c;
c=fun(a,b);
AfxMessageBox("Call me! No Exception is throwed in fun()");
}
catch(char* errMes)
{
AfxMessageBox(errMes);
}
比如
INT FUN()
{
....//1
TRY{
...//2
}
CATCH(...)
{
}}
会不会第一部分错了,然后影响到第二部分,然后在第而部分出错?
INT FUN()//相当于是WinMain或main主函数
{
....//1--相当于是int fun(int m,int n){}
TRY{
...//2--相当于是 c=fun(a,b);
}
CATCH(...)--相当于是catch(char* errMes) {
}}