Multiple Catch Statements

Description:

Write c++ program to handle multiple exception catch block, default catch block and re-throwing exceptions. Get two inputs from the user and the input is 0 or less than or character, string then display the exception as "Wrong Input" Mandatory: Use Try Catch If the input is valid number (Positive decimal or whole number) then print the number else print the exception as "Wrong Input" Test Case 1 Input (stdin) 5 srm srmuniv -23 12 2.22 Expected Output Wrong Input Wrong Input Wrong Input 12 2.22 Test Case 2 Input (stdin) 5 12 ulc elab ethink ecurricula Expected Output 12 Wrong Input Wrong Input Wrong Input Wrong Input

Program :

#include <iostream>
using namespace std;
int main()
{
char a[50];
  int n,i;
  cin>>n;
  for(i=0;i<n;i++)
  {
  cin>>a;
    try
    {
    if(atoi(a)<=0) throw a;
    else if(a[0]>58) throw a;
      cout<<a<<endl;
      }
    catch(char a[])
    {
    cout<<"Wrong Input\n";
    }}
 return 0;
}