1. Specifying exceptions
T funnname (parameterlist) throw (T1, t2,,tn);
Where T is the type, parameterlist is the argument list, and the type T1, t2,,tn is the exception that the function throws.
2. No exception thrown
T funnname (parameterlist) throw ();
The list of thrown exception types is empty, which means that the function does not throw any type exceptions.
3. Throw any type of exception
T Funnname (parameterlist);
This means that the function can throw any type of exception.
#include <iostream>
Class demo
{
};
using namespace Std;
Double divd (int a, int b) throw (Demo)//exception description, indicating that the function Divd throws an exception of type int
{
if (b = = 0) throw demo ();//Throw type Often
return a/b;
}
Int main ()
{
Try
{
Divd (1,0);
}
catch (Demo)//Catch Exception type demo
{
cout << "divided by zero" << Endl;
}
return 0;
}