异常处理问题~~

时间:2008-05-10 19:52:28   来源:论坛整理  作者:  编辑:chinaitzhe
麻烦给看一下下面的代码错在哪里
#include <iostream>
using namespace std;
void f(){
cout < <"f() called" < <endl;
range_error r("error");
exception *p=&r;
throw *p;

}
int main(){
try {f();}
catch(exception *&e) //这里应该怎样定义呢??
{cout < <(*e).what() < <"OK,capture the exception" < <endl;}
cout < <"Normal execution" < <endl;

return 0;
}
网友回复:
C/C code





Code highlighting produced by Actipro CodeHighlighter (freeware)

http://www.CodeHighlighter.com/



#include <iostream>

using namespace std;



void f()

{ 

    cout <<"f() called" <<endl; 

    range_error r("error"); 

    exception *p=&r; 

    throw *p; 

} 

int main()

{ 

    try {

        f();

    } 

    catch(exception& e)

    {

        cout <<e.what() <<"OK,capture the exception" <<endl;

    } 

    cout <<"Normal execution" <<endl; 



    return 0; 

}


网友回复:#include <iostream>
using namespace std;
void f(){
cout < <"f() called" < <endl;
range_error r("error");
exception *p=&r;
throw p;

}
int main(){
try {f();}
catch(exception *&e) //这里应该怎样定义呢??
{cout < <(*e).what() < <"OK,capture the exception" < <endl;}
cout < <"Normal execution" < <endl;

return 0;
}
网友回复:来接点分,不太清楚
关键字:异常,处理问题,

相关文章

文章评论

共有 0 位网友发表了评论 此处只显示部分留言 点击查看完整评论页面