当前位置: 首页>>C/C++语言>> 阅读正文

《C++ Primer plus》学习笔记之”异常”

Category: C/C++语言 View: 147,281 Author: Dong
,

  • 评论 (1)
  • 引用通告 (0)
发表评论 发起引用

  • 1楼C++Geek 回复

    Post: 2012-07-06 15:59

    try
    {
    z = hmean(x, y);
    cout<<”when throwing exception, here could be reached!”<<endl; //语句1
    }
    catch(const char *s)
    { //遇到异常,会在此捕获
    cout<<s<<endl; //遇到异常,会打印“bad hmean() arguments: a = -b not allowed” continue;
    }
    cout<<”continue…”<<endl; //语句2
    }

    There are two errors in above code.
    First:
    cout<<”when throwing exception, here could be reached!”<<endl; //语句1

    should be:

    cout<<”when throwing exception, here could NOT be reached!”<<endl; //语句1

    Second:
    continue; should be cout << "continue..".
    continue is only good with do, for and while.

    [回复]

目前还没有任何Trackbacks和Pingbacks.
发表评论