为什么...(三分)在catch块存在? [英] why ... (three points) in catch block is exist?

查看:196
本文介绍了为什么...(三分)在catch块存在?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在try catch语句中,我们可以做:

  try {} 
catch }

据我所知, ... :为什么C ++标准选择这种方式(...) 而不是()?例如,在函数中,如果你不需要参数你只需把()

  void foo(); 

它与变化模板有什么关系吗?

解决方案

catch()



但这不是真的,

  catch (...){
throw;
}

实际上重新抛出


In the try catch statement we can do:

try{}
catch(...){}

As far as I know, ... means any exception.

My question is: Why the C++ standard chose this way (...) instead of just ()? while, for example, in functions if you do not need parameters you just put ():

void foo();

Is it related to variadic templates in any way?

解决方案

catch() would imply strongly that nothing was passed to that particular catch block.

But that is not true,

catch(...){
    throw;
}

actually re-throws the exception caught by ...

这篇关于为什么...(三分)在catch块存在?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆