User Tools

Site Tools


c_-_c_exception_handling:class_exceptions

C - C++ Exception Handling - Class Exceptions

#include <iostream>
#include <cstring>
using namespace std;
 
class forgetcode 
{
public:
  char Error[80];
 
  forgetcode() { 
    cout<<"Error has occurred";
  }
 
  void display()
  {
    cout<<"\nPlease Enter a positive number";
  }
};
 
 
int main()
{
  int i;
 
  try {
    cout << "Enter a positive number: ";
    cin>>i;
 
    if(i<0)
      throw forgetcode();
    else
      cout<<"\nThe entered number is "<<i;
  }
  catch (forgetcode f) { 
    f.display();
  }
 
  return 0;
}
c_-_c_exception_handling/class_exceptions.txt · Last modified: 2020/07/15 09:30 by 127.0.0.1

Donate Powered by PHP Valid HTML5 Valid CSS Driven by DokuWiki