Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

why ... (three points) in catch block is exist?

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?

like image 726
Humam Helfawi Avatar asked Oct 31 '25 04:10

Humam Helfawi


1 Answers

It has nothing to do with variadic templates, because those came in C++11 whereas catch (...) existed from nearly the beginning (about two decades earlier).

As for why they chose (...) instead of (), you could ask Bjarne Stroustrup, but it hardly seems important. This feature isn't used all that often anyway. In C++, (...) usually means something like "Any number of things of any types" whereas () usually means "Nothing." Depending on your perspective, either one of these might be more preferred for "catch all exceptions."

like image 133
John Zwinck Avatar answered Nov 01 '25 18:11

John Zwinck



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!