#include <iostream>
#include <string>
using namespace Std;
int main ()
{
Try
{
int value1,value2; Define two integer variables
cout<< "Pleaseinput-value:" <<endl; Prompt to enter information
cin>>value1>>value2; Enter two integer numbers from the keyboard
cout<< "Maybeexception Code:" <<endl; Code message indicating that an exception may occur
if (value2== 0)//If the divisor is 0 throws an exception
{
Throw 0;
}
else//Otherwise direct COMPUTE division operation
{
cout<< "Value1/value2:" << (value1/value2) <<endl;
}
}catch (int i)//catch parameter is an integer type exception
{
cout<< "Divisoris 0!" <<endl; Exception handling code
}
return 0;
}
Once an exception is thrown, a catch is executed, no corresponding catch program is thrown, and a statement that is not executed behind the try is no longer executed.
A try body can throw an exception directly or indirectly in the body of a function called in the try body.
A try block can contain one or more exception throw points. It is important to note, however, that if an exception is thrown, the corresponding catch block is snapped, and the following code body execution in the try block is terminated. The code executes directly into the corresponding catch block, and the last catch block executes after the exception has been processed and jumps directly to the catch block corresponding to all the current try blocks.
try{
Throw ....
}catch () {}
C + + Exception capture