exceptions 24

exceptions 24 - C+ Exception Handling The Basics throw try...

Info iconThis preview shows pages 1–5. Sign up to view the full content.

View Full Document Right Arrow Icon
C++ Exception Handling
Background image of page 1

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
C++ Exception Handling 2 The Basics throw try catch class MyException { }; class MyOtherException { }; void f (int foo) throw (MyException, MyOtherException) { (foo == 0) ? throw MyException() : throw MyOtherException(); } int main() { for ( int index = 0; index < 10; ++index) try { f(index); } catch(MyException) { cout << “caught myexception” << endl; } catch(MyOtherException) { cout << “caught myotherexception” << endl; } }
Background image of page 2
C++ Exception Handling 3 The Exception Hierarchy class exception Defines the base class for the types of objects thrown as exceptions by the other library components Found in <exception> class logic_error Derived from the exception class Found in <stdexcept> Represents errors caused by problems in the internal logic of the program. They are generally preventable. Exception classes derived from logic_error include: domain_error, invalid_argument, length_error, out_of_range
Background image of page 3

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
C++ Exception Handling 4
Background image of page 4
Image of page 5
This is the end of the preview. Sign up to access the rest of the document.

This note was uploaded on 03/17/2010 for the course CS 162 taught by Professor Fant during the Spring '08 term at Portland State.

Page1 / 7

exceptions 24 - C+ Exception Handling The Basics throw try...

This preview shows document pages 1 - 5. Sign up to view the full document.

View Full Document Right Arrow Icon
Ask a homework question - tutors are online