Exception description of C + + exception

Source: Internet
Author: User

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.