Reputation: 623
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?
Upvotes: 1
Views: 757
Reputation: 146910
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.
Upvotes: 2
Reputation: 385104
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 (...);
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)`
}
Upvotes: 3