Ask Question

How can an exception be explicitly raised in C++? How are exceptions bound to handlers in C++?

+4
Answers (1)
  1. 1 September, 21:41
    0
    Exceptions are raised using throw statement in c++.

    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

    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";

    }

    }
Know the Answer?
Not Sure About the Answer?
Find an answer to your question 👍 “How can an exception be explicitly raised in C++? How are exceptions bound to handlers in C++? ...” in 📗 Computers & Technology if the answers seem to be not correct or there’s no answer. Try a smart search to find answers to similar questions.
Search for Other Answers