Yurttas/PL/OOL/Cplusplus/F/02/06/03/exception 02.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_02.cpp
14*/
15
16
17#include <iostream>
18#include <cctype>
19
20using namespace std;
21
22#include "Thrower.h"
23
24enum IDC {Integer='I',
25          Double='D',
26          Character='C'};
27
28typedef enum IDC IDC;
29
30int main(int argc, char* argv[]) {
31
32  char decision;
33
34  cout << "Enter a decision value as character I | D | C : ";
35  cin >> decision;
36
37  try {
38    switch((IDC)(toupper(decision))) {
39      case Integer : {
40        int value; 
41
42        cout << "Enter an int value : " ;
43        cin >> value;
44
45        Thrower().thrower(value); // unhandled exception 
46      }
47      break;
48
49      case Double : {
50        double value; 
51
52        cout << "Enter a double value : " ;
53        cin >> value;
54
55        Thrower().thrower(value); // unhandled exception 
56      }
57      break;
58
59      case Character : {
60        char value; 
61
62        cout << "Enter a char value : " ;
63        cin >> value;
64
65        Thrower().thrower(value); // unhandled exception 
66      }
67    }
68  }
69  catch(const int value) {
70    cerr << "Integer Exception : " << value << endl;
71  }
72  catch(const double value) {
73    cerr << "Double Exception : " << value << endl;
74  }
75  catch(const char value) {
76    cerr << "Character Exception : " << value << endl;
77  }
78
79}