1

I have a question regarding declaration class method in C++. I usually using declaration method without providing throw (will throw anything). But I saw somewhere declaration like this:

void method(int param) throw (...);

Does it have any sense? What is difference?

Csq
  • 5,775
  • 6
  • 26
  • 39
Vladislav Krejcirik
  • 593
  • 2
  • 6
  • 10
  • 2
    Do you mean `throw (...)` literally? Or `throw (something here)`? If the latter then this is a duplicate of http://stackoverflow.com/questions/1589459/what-is-the-point-of-void-func-throwtype (which appears right there at the top of the "Related" list, as it did whilst you were writing your question). – Lightness Races in Orbit Jun 30 '14 at 11:05
  • I mean throw(...) literally. – Vladislav Krejcirik Jun 30 '14 at 11:28

2 Answers2

3

Well it's not valid C++ so, no, it doesn't "have any sense":

g++ -std=c++11 -O2 -Wall -pedantic -pthread main.cpp && ./a.out
main.cpp:1:31: error: expected type-specifier before '...' token
 void method(int param) throw (...);

(nor in C++03)

The only place you can write ... in an exception specifier is after the type-id in a dynamic-exception-specification in order to form a pack expansion ([C++11: 15.4/16]), like so:

template <typename ...T>
void method(int param) throw (T...) {}

int main()
{
    method<int, bool>(42);
    // ^ somewhat like invoking a `void method(int) throw(int, bool)`
}
Lightness Races in Orbit
  • 378,754
  • 76
  • 643
  • 1,055
2

It's a Microsoft extension, which basically means "This function may throw something", which is equivalent to having no specification at all. The value of adding it is questionable.

Puppy
  • 144,682
  • 38
  • 256
  • 465
  • 1
    For completeness: it also works with Clang 3.5 for me, but not with `g++ -fms-extensions`. – xaizek Jun 30 '14 at 11:45