关于runtime_error的问题

strtsoia 2011-01-19 06:56:49
按照c++ primer上的程序,
if (argc != 3)
throw runtime_error("wrong number of arguments");
我故意把参数输入不是三个,然后应该抛出异常wrong number of arguments,但是我却是程序中断,显示
This application has requested the Runtime to terminate it in an unusual way.
Please contact the application's support team for more information.有谁知道为什么runtime_error不能执行报错处理,然后程序terminate了
...全文
281 13 打赏 收藏 转发到动态 举报
写回复
用AI写文章
13 条回复
切换为时间正序
请发表友善的回复…
发表回复
bluesky12312388 2011-01-19
  • 打赏
  • 举报
回复
try{
if (argc != 3)
throw runtime_error("wrong number of arguments");
}
catch(runtime_error &err)
{
cout<<err.what()<<endl;
}

改成这样在试试看
luciferisnotsatan 2011-01-19
  • 打赏
  • 举报
回复
你又没捕获异常

还是你使用了set_terminate或set_unexpected,但程序没调用你设置的函数?
bdmh 2011-01-19
  • 打赏
  • 举报
回复
你这样当然中断了,异常在try/catch中捕获
qq120848369 2011-01-19
  • 打赏
  • 举报
回复
catch(const runtime_error &err)


If no matching catch is found, then the program calls the library terminate function.Usually,terminate call the library function abort to exit the program.

ForestDB 2011-01-19
  • 打赏
  • 举报
回复
你try/catch试试?
野男孩 2011-01-19
  • 打赏
  • 举报
回复
你抛出的就是个runtime_error啊。。。。。
maoxing63570 2011-01-19
  • 打赏
  • 举报
回复
An exception cannot remain unhandled. An exception is an important enough event that the program cannot continue executing normally. If no matching catch is found, then the program calls the library terminate function.Usually,terminate call the library function abort to exit the program.
管哥的天下 2011-01-19
  • 打赏
  • 举报
回复
自己抛出的异常,被自己接收,但是楼主没有自己对异常进行处理!那就会按照系统自己定义的方式进行处理!
jsjygm 2011-01-19
  • 打赏
  • 举报
回复
应该再tyr|catch里。
zy020118 2011-01-19
  • 打赏
  • 举报
回复
[Quote=引用 5 楼 bluesky12312388 的回复:]
C/C++ code
try{
if (argc != 3)
throw runtime_error("wrong number of arguments");
}
catch(runtime_error &err)
{
cout<<err.what()<<endl;
}

改成这样在试试看
[/Quote]
+1
strtsoia 2011-01-19
  • 打赏
  • 举报
回复
各位,我只想知道直接runtime_error("wrong argument number")为什么不行呢,书上就是这样的啊,而且确实有runtime_error这个类的,是标准库里的.
Metrosexual 2011-01-19
  • 打赏
  • 举报
回复
[Quote=引用 5 楼 bluesky12312388 的回复:]
C/C++ code
try{
if (argc != 3)
throw runtime_error("wrong number of arguments");
}
catch(runtime_error &err)
{
cout<<err.what()<<endl;
}

改成这样在试试看
[/Quote]
+1

64,663

社区成员

发帖
与我相关
我的任务
社区描述
C++ 语言相关问题讨论,技术干货分享,前沿动态等
c++ 技术论坛(原bbs)
社区管理员
  • C++ 语言社区
  • encoderlee
  • paschen
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
  1. 请不要发布与C++技术无关的贴子
  2. 请不要发布与技术无关的招聘、广告的帖子
  3. 请尽可能的描述清楚你的问题,如果涉及到代码请尽可能的格式化一下

试试用AI创作助手写篇文章吧