summaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorven <vendethiel@hotmail.fr>2015-06-03 09:16:26 +0200
committerven <vendethiel@hotmail.fr>2015-06-03 09:16:26 +0200
commit9e44a5b9eec2017ae33ca213efd1c0b1c86e93cb (patch)
treedc4e1374796473410bc91531044ce5133360c107
parentc5b12a3af433f3da5a3c10c940b30e60af166217 (diff)
parent06889be239622266d9c36c750f7ee755ccdae05d (diff)
Merge pull request #1123 from adamheins/master
[c++/en] Make code compileable.
-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);