Software School Projects | Academic Students Projects | Source Codes | Tablets header
Please use our contact us form or send email to Support@srishtis.com.

Invoking Function That Generates
Exception
 

//Throw point outside the try block


#include<iostream>

using namespace std;

void divide(int x, int y, intz)

{

cout<<"\n We are inside the function \n";

if((x-y)!= 0) //It is ok

{

int R =z/(x-y);

cout<<"Result=" <<R<<"\n";

}

else //There is a problem

{

throw(x-y); //Throw point

}

}

int main()

{

try

{

cout<<"We are inside the try block \n";

divide(10,20,30); //Invoke divide()

divide(10,10,20); //Invoke divide()

}

catch(int i) //Catches the exception

{

cout<<"Caught the exception \n";

}

return 0;

}

 

 

 


 
 
Job or extra money for students

Search Engine Rank of your blog or websites