Exception catch block question

Started by
3 comments, last by Genjix 18 years, 10 months ago
In Visual C++, Microsoft says you can use the following to catch any exception

try
{
    throw SomeException();
}
catch(...) // This syntax
{
    std::cout << "An Exception Was Thrown" << std::endl;
}

I don't have access to a non Microsoft compiler at the moment. I get the impression from the MSDN documentation, that catch(...) is Microsoft specific. I just want to confirm this. If it is Microsoft specific, do compilers like gcc have their own method of catching any exception? Or is this universal (which I doubt).

"I can't believe I'm defending logic to a turing machine." - Kent Woolworth [Other Space]

Advertisement
each compiler that ive worked on has supported ellipses (...) in the catch statement, and as a function parameter. So your answer is no, this is not microsoft specific.
from the ISO C++ standard:
Quote:
15.3 - Handling an exception [except.handle]

... snip ...

-6- A ... in a handler's exception-declaration functions similarly to ... in a function parameter declaration; it specifies a match for any exception. If present, a ... handler shall be the last handler for its try block.

... snip ...
Thanks a lot. That's exactly what I needed to know.

"I can't believe I'm defending logic to a turing machine." - Kent Woolworth [Other Space]

yes I use it regularly in high level exception blocks for safety.

This topic is closed to new replies.

Advertisement