Caching Exception in C++

Estudies4you
Notes on Caching exception in C++
CATCHING AN EXCEPTION 
Q15. Explain in detail about catching an exception. 
Answer: 
The catch block handles an exception thrown by the try The general syntax of catch block is shown below, 

catch( type argument) 

{

//code 

A catch block takes an argument as an exception. These arguments specify the type of an exception that can be handled by the catch block. When an exception is thrown the control goes to catch block. If the type of exception thrown matches the argument then the catch block is executed, otherwise the program terminates abnormally. If no exception is thrown from the try block then the catch block is skipped and control goes immediately to the next statement following the catch block.

Program 

#include<iostream> 

#include<string> 

using namespace std: 

int main() 

{

int a, b, c; 

cout <<"Enter the value of a: "; 

cin:>>a; 

cout "Enter the value of b:; 

cin>>b; 

try 

{

if(b)=0)

{

throw b; 

}

else 

if (b < 0) 

{

throw "Negative denominator not allowed"; 

}

c = a/b; 

cout<<"\nThe value of c is:" <<c; 

}

catch(int num) 

{

cout<<"You cannot enter "<<num<<" in denominator."; 

}

}

Output 

Examples of Caching Exception in C++,what is Caching Exception in C++,define caching exception in c++,Caching Exception notes,define Caching Exception,use of Caching Exception in C++


To Top