Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // C-pp Program to introduce a class type as an exception
- // Author : fueanta
- #include <iostream>
- #include <conio.h>
- using namespace std;
- class Error {
- int error_no;
- //char *error_desc;
- string error_desc;
- public:
- Error(int n, /*char* d*/ string d) {
- error_no= n;
- //error_desc= new char[strlen(d)];
- //strcpy(error_desc,d);
- error_desc= d;
- }
- void err_disp(void) {
- cout << "Error No: " << error_no << endl;
- cout << "Error Description: " << error_desc << endl;
- }
- };
- int main(void) {
- try{
- cout << "Press any key to continue." << endl;
- getch();
- throw Error(123,"Error #506");
- }
- catch(Error E) {
- cout << "An error occurred." << endl;
- E.err_disp();
- }
- getch();
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement