Introducing Radical.sh

Forget Code launches a powerful code generator for building API's

Class Type Exceptions in C++

#include <iostream>
#include <cstring>
using namespace std;
 
class forgetcode {
public:
  char Error[80];
  
  forgetcode() { 
  cout<<"Error has occured";
  }
 
  void display()
  {
      cout<<"\nPlease Enter a positve 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;
}