16,472
社区成员
发帖
与我相关
我的任务
分享
void DoSomeOperation( )
{
// Processing
// If something goes wrong...
AfxMessageBox( "The x operation failed" );
AfxThrowUserException( );
}
BOOL TrySomething( )
{
TRY
{
// Could throw a CUserException or other exception.
DoSomeOperation( );
}
CATCH( CUserException, e )
{
return FALSE; // User already notified.
}
AND_CATCH( CException, e )
{
// For other exception types, notify user here.
AfxMessageBox( "Some operation failed" );
return FALSE;
}
END_CATCH
return TRUE; // No exception thrown.
}
#include <iostream>
using namespace std;
struct MyStruct {
int Nodedata;
MyStruct *pLeft;
MyStruct *pRight;
} s1,s2,s3,s4,s5,s6,s7,s8;
void ashow(MyStruct * p) {
if (p != nullptr) {
ashow(p->pLeft);
ashow(p->pRight);
cout << p->Nodedata << endl;
if (p->Nodedata == 4) {
throw 1;//退出递归.直接返回.
}
}
}
int main() {
MyStruct *pRoot;//根
pRoot = &s1;
s1.Nodedata = 1;
s2.Nodedata = 2;
s3.Nodedata = 3;
s4.Nodedata = 4;
s5.Nodedata = 5;
s6.Nodedata = 6;
s7.Nodedata = 7;
s8.Nodedata = 8;
s1.pLeft = &s2;
s1.pRight = &s3;
s2.pLeft = &s4;
s2.pRight = &s5;
s3.pLeft = &s6;
s3.pRight = &s7;
try {
ashow(pRoot);
} catch (int err) {
cout<<"catch err "<<err<<endl;
}
return 0;
}
//4
//catch err 1
//