C++编程(C)

Educn void h try matherr catchmatherr

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: osts & Telecommunications Beijing young@buptnet.edu.cn 14.2 异常的结组(Grouping of Exceptions) 一个异常也就是某个用于表示异常发生的类 的一个对象 一个throw的作用就是导致堆栈的一系列回 退,直到找到某个适当的catch 异常经常可以自然地形成一些族,意味着可 以借助于继承来描述异常的结构 异常的类层次结构表示对于代码的健壮性可 能很重要,考虑:若没有结组机制,如何处 理来自数学库的所有异常 Beijing University of Posts & Telecommunications Beijing young@buptnet.edu.cn 异常的结组示例 class Matherr{}; class Overflow:public Matherr{}; class Underflow:public Matherr{}; class Zerodivide:public Matherr{}; void f(){ try { // … } catch(Overflow){ // 处理Overflow或者任何由Overflow派生的异常 } catch(Matherr){ // 处理所有不是Overflow的Matherr } } Beijing University of Posts & Telecommunications Beijing young@buptnet.edu.cn 异常的结组示例 void g() { try{ //... } catch...
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