mirror of
https://github.com/adambard/learnxinyminutes-docs.git
synced 2024-12-23 15:24:09 +03:00
Using std::runtime_error instead of std::exception.
This commit is contained in:
parent
47d3cea47e
commit
894792e1e1
@ -519,12 +519,13 @@ printMessage<10>(); // Prints "Learn C++ faster in only 10 minutes!"
|
|||||||
// (see http://en.cppreference.com/w/cpp/error/exception)
|
// (see http://en.cppreference.com/w/cpp/error/exception)
|
||||||
// but any type can be thrown an as exception
|
// but any type can be thrown an as exception
|
||||||
#include <exception>
|
#include <exception>
|
||||||
|
#include <stdexcept>
|
||||||
|
|
||||||
// All exceptions thrown inside the _try_ block can be caught by subsequent
|
// All exceptions thrown inside the _try_ block can be caught by subsequent
|
||||||
// _catch_ handlers.
|
// _catch_ handlers.
|
||||||
try {
|
try {
|
||||||
// Do not allocate exceptions on the heap using _new_.
|
// Do not allocate exceptions on the heap using _new_.
|
||||||
throw std::exception();
|
throw std::runtime_error("A problem occurred");
|
||||||
}
|
}
|
||||||
// Catch exceptions by const reference if they are objects
|
// Catch exceptions by const reference if they are objects
|
||||||
catch (const std::exception& ex)
|
catch (const std::exception& ex)
|
||||||
|
Loading…
Reference in New Issue
Block a user