Advertisement
fueanta

Class Type as an Exception

Sep 6th, 2016
173
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.82 KB | None | 0 0
  1. // C-pp Program to introduce a class type as an exception
  2. // Author : fueanta
  3. #include <iostream>
  4.  
  5. #include <conio.h>
  6.  
  7. using namespace std;
  8.  
  9. class Error {
  10.     int error_no;
  11.     //char *error_desc;
  12.     string error_desc;
  13. public:
  14.     Error(int n, /*char* d*/ string d) {
  15.         error_no= n;
  16.         //error_desc= new char[strlen(d)];
  17.         //strcpy(error_desc,d);
  18.         error_desc= d;
  19.     }
  20.     void err_disp(void) {
  21.         cout << "Error No: " << error_no << endl;
  22.         cout << "Error Description: " << error_desc << endl;
  23.     }
  24. };
  25.  
  26. int main(void) {
  27.     try{
  28.         cout << "Press any key to continue." << endl;
  29.         getch();
  30.         throw Error(123,"Error #506");
  31.     }
  32.     catch(Error E) {
  33.         cout << "An error occurred." << endl;
  34.         E.err_disp();
  35.     }
  36.     getch();
  37.     return 0;
  38. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement