summaryrefslogtreecommitdiffhomepage
path: root/c++.html.markdown
diff options
context:
space:
mode:
Diffstat (limited to 'c++.html.markdown')
-rw-r--r--c++.html.markdown6
1 files changed, 4 insertions, 2 deletions
diff --git a/c++.html.markdown b/c++.html.markdown
index 5cd491b9..ff2a98fd 100644
--- a/c++.html.markdown
+++ b/c++.html.markdown
@@ -445,6 +445,7 @@ int main () {
// define a class or function that takes a type parameter:
template<class T>
class Box {
+public:
// In this class, T can be used as any other type.
void insert(const T&) { ... }
};
@@ -518,12 +519,13 @@ printMessage<10>(); // Prints "Learn C++ faster in only 10 minutes!"
// (see http://en.cppreference.com/w/cpp/error/exception)
// but any type can be thrown an as exception
#include <exception>
+#include <stdexcept>
// All exceptions thrown inside the _try_ block can be caught by subsequent
// _catch_ handlers.
try {
// Do not allocate exceptions on the heap using _new_.
- throw std::exception("A problem occurred");
+ throw std::runtime_error("A problem occurred");
}
// Catch exceptions by const reference if they are objects
catch (const std::exception& ex)
@@ -614,7 +616,7 @@ void doSomethingWithAFile(const char* filename)
{
FILE* fh = fopen(filename, "r"); // Open the file in read mode
if (fh == nullptr)
- throw std::exception("Could not open the file.");
+ throw std::runtime_error("Could not open the file.");
try {
doSomethingWithTheFile(fh);