Program to catch all type of Exceptions in C++

 #include <iostream>

using namespace std;

#include <string>

int main()

{

      string Name = "Vaibhav_Yadav", R_Name;

      int Roll = 2021071042, roll_no;

      cout<<"Authentication Please Verify Yourself"<<endl;

      try{

            cout<<"Enter Your Name: ";

            getline(cin, R_Name);

            cout<<"Enter Your Roll No: ";

            cin>>roll_no;

            if(R_Name == Name && Roll == roll_no){

                  cout<<"Login Success"<<endl;

            }else{

                  throw 401;

            }

      }

      catch(...){

            cout<<"Authentication failed"<<endl;

            cout<<"Access Not Allowed"<<endl;

      }


    return 0;

}


No comments:

Post a Comment

Operator Overloading in C++

#include<iostream> using namespace std; class Complex { private: int real, imag; public: Complex(int r = 0, int i = 0){       re...