188k views
2 votes
How can an exception be explicitly raised in C++? How are exceptions bound to handlers in C++?

1 Answer

3 votes

Answer:

Exceptions are raised using throw statement in c++.

Step-by-step explanation:

Try block is used to keep the statements which we felt that they will raise an exception. Catch block is used to catch the exception which is thrown by the try block.

#include<iostream.h>

void main(){

int x,y,z;

try{

cout<"enter 2 numbers";

cin>>x>>y;

if(y==0)

throw y;

z=x/y;

}

catch(int x){

cout<<"exception caught";

}

}

User Colinta
by
5.7k points