C++编程(C)

catchbadalloc catch setnewhandleroldnh

Info iconThis preview shows page 1. Sign up to view the full content.

View Full Document Right Arrow Icon
This is the end of the preview. Sign up to access the rest of the document.

Unformatted text preview: atch(std::ios_base::failure){ //处理任何流io错误 } catch(std::exception& e){ //处理所有标准库异常 } catch(...){ //处理任何其他异常 } } Beijing University of Posts & Telecommunications Beijing young@buptnet.edu.cn 处理器的顺序 void f() { try{ //... } catch(...){ //处理任何其他异常 } catch(std::exception& e){ //处理所有标准库异常 } catch(std::bad_cast){ //处理dynamic_cast失败 } } 如果次序安排的不 好,有些异常处理代 码将永远不会运行 左例中,bad_cast 部分将永远不被执 行,即使将catch(…) 部分去掉也不行 Beijing University of Posts & Telecommunications Beijing young@buptnet.edu.cn 14.4 资源管理 当函数申请了某种资源(打开文件或者分配 空间)时,一个很重要的问题就是需要正确 释放这些资源 是如果程序在运行过程中产生了异常,就 会导致程序的流程不是所希望那样,此时需 特别注意资源问题 异常产生时,实现...
View Full Document

This note was uploaded on 02/10/2014 for the course ECE C++ taught by Professor Xiaoshengtang during the Fall '13 term at BUPT.

Ask a homework question - tutors are online