4

I have seen in the Visual C++ include file <vector> using throw() after a function:

size_type capacity() const _NOEXCEPT
    {   // return current length of allocated storage
    return (this->_Myend - this->_Myfirst);
    }

With the _NOEXCEPT a macro for throw(), so the above looks like:

size_type capacity() const throw()
    {   // return current length of allocated storage
    return (this->_Myend - this->_Myfirst);
    }

But what does the throw do? I have seen in this question why it is a bad practise, but why has it been put there when nothing is thrown or caught?

Community
  • 1
  • 1
Joe
  • 1,059
  • 2
  • 11
  • 21
  • 1
    possible duplicate of [What is the benefit to limiting throws allowed by a C++ function?](http://stackoverflow.com/questions/609332/what-is-the-benefit-to-limiting-throws-allowed-by-a-c-function) – user1810087 Jan 04 '14 at 10:59

1 Answers1

4

The throw exception specification is deprecated in C++11 and replaced by noexcept.

From http://en.cppreference.com/w/cpp/language/noexcept_spec:

noexcept is an improved version of throw(), which is deprecated in C++11. Unlike throw(), noexcept will not call std::unexpected and may or may not unwind the stack, which potentially allows the compiler to implement noexcept without the runtime overhead of throw().