C + + Exception 1

Source: Internet
Author: User

include <iostream>                                                                 #include  <cstdio>using  namespace std;class a{public:    a (void) {cout <<  "A::A ()"  << endl;}     ~a (void) {cout <<  "a::~a ()"  << endl;}}; Int func3 (void) {    a a;    file *fp = fopen ( "None.txt", "R");     if (!FP) {        throw -1 ;//Throws an exception, jumps to the current scope "}", this exception can be either a basic type or a class type         cout <<   "FUNC3"   << endl;//do not perform     }       fclose (FP);     return 0;} Int func2 (void) {    a a;    func3 (); After the//FUNC3 function throws an exception, In the function Func2 is not able to handle, the exception is then thrown,             //so Z jumps directly to this scope "} "    cout << " Func2 " << endl;//will not execute      return 0;//does not perform}int func1 (void) {&NBSP;&NBSP;&NBSP;&NBSP;A&NBSP;A;&NBSP;&NBSP;&NBSP;&NBSP;FUNC2 ( );//func1 failed to handle exceptions from FUNC2, throwing exceptions, jumping directly to the scope of "}"     cout <<  "Func1"  < < endl;//do not perform     return 0;//do not perform}int main (void) {     Try{        func1 ();         //     }    catch (INT&NBSP;EX) {//try statement block below must be a catch statement block, other statements are error, here the catCH Capture                    //to the exception, and then continue to execute .     cout <<  "ex="  << ex < < endl;        cout <<  "file open  Error " << endl;        return -1;     }    return 0;}


This article is from the "12208412" blog, please be sure to keep this source http://12218412.blog.51cto.com/12208412/1869192

C + + Exception 1

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.