C++编程(C)

beijing university of posts telecommunications

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: or"; } }; void f() { try { g(); } catch(Matherr m){/*...*/ } } 即使g()抛出的实际上是一 个Int_overflow,这里m 仍然一个Matherr对象,也 即:Int_overflow所携带 的附加信息将是不可访问的 class Int_overflow:public Matherr{ const char* op; int a1, a2; public: Int_overflow(const char* p,int a,int b){ op = p; a1 = a; a2 = b; } 若需要访问附加信息, virtual void debug_print() const { catch后面括号中应该声明 cerr << op << a1 << a2; } 为Matherr的引用或者指针 }; Beijing University of Posts & Telecommunications Beijing young@buptnet.edu.cn 14.2.2 多个异常的组合 并不是每组异常都具有树形结构,也常有一 个异常同属于两个组的情况,如下,这样的 一个Netfile_err异常能够被处理网络的异 常捕获,也能被处理文件系统异常的函数捕 获 对于错误处理的这种非层次性结构的组织形 式很重要,否则用户或许根本意识不到自己 捕获了某个异常 class Netfile_err...
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