Go back to Richel Bilderbeek's homepage.

Go back to Richel Bilderbeek's C++ page.

 

 

 

 

 

(C++) throw

 

throw is the keyword to produce an exception.

 

#include <exception>

int main()
{
  throw std::exception();
}

 

A try-block indicates the calling of functions that might throw an exception and is followed by a catch-block, where the exception is handled.

 

 

 

 

 

Advice

 

 

 

 

 

 

Reference

 

  1. Bjarne Stroustrup. The C++ Programming Language (4th edition). 2013. ISBN: 978-0-321-56384-2. Chapter 13.7. Advice. page 386: '[2] Throw an exception to indicate that you cannot perform an assigned task'
  2. Bjarne Stroustrup. The C++ Programming Language (4th edition). 2013. ISBN: 978-0-321-56384-2. Chapter 13.7. Advice. page 387: '[11] Let a constructor establish an invariant, and throw if it cannot'
  3. Bjarne Stroustrup. The C++ Programming Language (4th edition). 2013. ISBN: 978-0-321-56384-2. Chapter 13.7. Advice, page 387: '[23] If your function may not throw, declare it noexcept'

 

 

 

 

 

Go back to Richel Bilderbeek's C++ page.

Go back to Richel Bilderbeek's homepage.

 

Valid XHTML 1.0 Strict