| void main() { //初始化 ... try { ProcessMail(...); } catch (int ret) { switch (ret) { case E_INITIALIZATION_FAILURE: ... case E_IRRECOVERABLE: ... ... } } } void ProcessMail(...) { //初始化 ... if ( initializationError ) { throw(E_INITIALIZATION_FAILURE); } while ( !shutdown ) { try { ReadMail(...) } catch (int ret) { switch (ret) { case E_READ_ERROR: //记录错误信息 ... //试图恢复 ... if ( recovered ) { continue; } else { throw(E_IRRECOVERABLE); } break; case ... } } //继续处理 ... } //throw()可以用来取代缺少的返回码 //但也要注意由此带来的性能损失 throw(S_OK); } // ProcessMail() void ReadMail(...) { ... //在此无须捕捉异常 nBytesAvailable = ReadBytes(...) ... } int ReadBytes(...) { //读取数据 if ( error ) { throw(E_READ_ERROR); } return nBytesRead; } |
| ·VC入门专区 | ·VC高级技术专区 | ||
| ·VC网络通讯编程 | ·VC图像编程 | ||
| ·轻松玩转MFC文档视图架构编程 | |||
| ·深入浅出Win32多线程程序设计 | |||
| ·深入浅出Visual C++动态链接库编程 | |||