try catch语法问题

a5796489 2011-07-07 04:31:10
try
{
...
}
catch
{
...
}
报错了,catch必须得给它加至少一个参数,catch(int i)这样随便加了下就不报错了,怎么回事?
...全文
167 10 打赏 收藏 转发到动态 举报
写回复
用AI写文章
10 条回复
切换为时间正序
请发表友善的回复…
发表回复
赵4老师 2011-07-07
  • 打赏
  • 举报
回复
[Quote=引用 5 楼 a5796489 的回复:]
zhao4zhong1
怎么每次上来都是一堆的英文啊,我英文实在不行请照顾下.......

catch(...) 这叫啥语法?
[/Quote]
英语也是一门计算机语言的说。

亡羊补牢,为时未晚!
a5796489 2011-07-07
  • 打赏
  • 举报
回复
可是直接打catch(...)是错的啊
太上绝情 2011-07-07
  • 打赏
  • 举报
回复
可能有很多种情况都要抛出,但你怎么判断是那种情况呢?,这就靠catch的参数来确定了。
就想叫yoko 2011-07-07
  • 打赏
  • 举报
回复
语法是人家制定语言的人定的
还能说啥
你只能学习语言的使用方法
無_1024 2011-07-07
  • 打赏
  • 举报
回复
你要知道捕获的是什么什么异常啊
或者写成 catch(...)
a5796489 2011-07-07
  • 打赏
  • 举报
回复
zhao4zhong1
怎么每次上来都是一堆的英文啊,我英文实在不行请照顾下.......

catch(...) 这叫啥语法?
就想叫yoko 2011-07-07
  • 打赏
  • 举报
回复
catch(...)
赵4老师 2011-07-07
  • 打赏
  • 举报
回复
Exception Handling Syntax
Home | Overview | How Do I | FAQ

The structure for C++ exception handling is represented by the following syntax:

try-block :
try compound-statement handler-list

handler-list :
handler handler-listopt

handler :
catch ( exception-declaration ) compound-statement

exception-declaration :
type-specifier-list declarator
type-specifier-list abstract-declarator
type-specifier-list
...

throw-expression :
throw assignment-expressionopt

The compound-statement after the try clause is the guarded section of code. The throw-expression throws an exception. The compound-statement after the catch clause is the exception handler, and catches the exception thrown by the throw-expression. The exception-declaration statement after the catch clause indicates the type of exception the clause handles. The type can be any valid data type, including a C++ class.

If the exception-declaration statement is an ellipsis (...), the catch clause handles any type of exception, including C exceptions as well as system-generated and application-generated exceptions. This includes exceptions such as memory protection, divide-by-zero, and floating-point violations. An ellipsis catch handler must be the last handler for its try block.

The operand of throw is syntactically similar to the operand of a return statement.

Microsoft Specific —>

Microsoft C++ does not support the function exception specification mechanism, as described in section 15.4 of the ANSI C++ draft.

END Microsoft Specific
a5796489 2011-07-07
  • 打赏
  • 举报
回复
怎么写?我不要它抓参数
就想叫yoko 2011-07-07
  • 打赏
  • 举报
回复
。。
语法问题啊
如果要捕抓所有异常就 catch ...

64,642

社区成员

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

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