Ch 11. Exception Handling


Click here to start

Table of Contents

Ch 11. Exception Handling


Flags and Return Codes

The stream I/O system does not return an error status flag directly, but rather it yields a value that can be converted into a boolean value that indicates the error:

errono should always be checked after calling any function in which it might be set.

The Assertion Library

The Assertion Library

The setjmp and longjmp Facility

# include <csetjmp> // include setjmp library ...

When encounter an unrecoverable error, programmer can invoke the longjmp, passing as an argument the jump buffer and a nonzero integer value, rather than tracking back through the sequence of function invocations :

Activation Record Stack


Exception Types

A class hierarchy in the header file stdexcept in STL

Catch-all exception handler in Java.

C++ permits ellipses to be used as the catch argument.

Rethrowing Exceptions

No finally Clause

class CleanUp { ~CleanUp () { // ... put common clean up code here } }; //... try { CleanUp dummy; //... } catch (IOError & e) { // ... } catch (RunTimeError & e) { // ... } // ... continue with execution

Reference as Exceptions

Exception Class Clonability

class ParseException { public: // constructors ParseException (string & why) : reason(why) { } ParseException (ParseException & why) : reason(why.reason) { } // operators void operator = (ParseException & why)

No Need to Document Exception

Always document a potential exception by placing a throw list in the function header.

Standard Exceptions

void f () throw (string)

Author: Seung Sean Yoo


Home Page: