Yurttas/PL/OOL/Cplusplus/F/02/06/04/00/exception 04.cpp

From ZCubes Wiki
Jump to navigation Jump to search
 1/*
 2   Copyright(C) 2000
 3   All Rights Reserved. Salih Yurttas, ZCubes, BitsOfCode Software Systems, Inc..
 4
 5   Permission to use, copy, modify, and distribute this
 6   software and its documentation for EDUCATIONAL purposes
 7   and without fee is hereby granted provided that this
 8   copyright notice appears in all copies.
 9
10   date   : January 1, 2000.
11   author : Salih Yurttas.
12
13   exception_04.cpp
14*/
15
16
17#include <iostream>
18
19#include <stdexcept>
20
21using namespace std;
22
23class E1;
24
25class E2;
26
27class E2 {
28public:
29  E2() {}
30};
31
32void handle_unexpected() {
33  throw bad_exception();
34}
35
36void f_00()
37  throw(E1,
38        bad_exception)
39{
40  throw E2();  // throw an exception not specified in the declaration
41}
42
43int main(int argc, char* argv[]) {
44
45  set_unexpected(handle_unexpected);
46
47  try {
48    f_00();
49  }
50  catch(bad_exception e) {
51    cout << "Exception : " << e.what() << endl; 
52  }
53
54}