Skip to content

Commit db03810

Browse files
committed
test09.cpp
1 parent 07a3dd3 commit db03810

1 file changed

Lines changed: 47 additions & 0 deletions

File tree

section2/test09.cpp

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
// Copyright (c) 2020 by Chrono
2+
//
3+
// g++ test09.cpp -std=c++11 -o a.out;./a.out
4+
// g++ test09.cpp -std=c++14 -o a.out;./a.out
5+
// g++ test09.cpp -std=c++14 -I../common -o a.out;./a.out
6+
7+
#include <iostream>
8+
#include <stdexcept>
9+
10+
using namespace std;
11+
12+
class my_exception : public std::runtime_error
13+
{
14+
public:
15+
using this_type = my_exception;
16+
using super_type = std::runtime_error;
17+
public:
18+
my_exception(const char* msg):
19+
super_type(msg)
20+
{}
21+
22+
my_exception() = default;
23+
~my_exception() = default;
24+
};
25+
26+
[[noreturn]]
27+
void raise(const char* msg)
28+
{
29+
throw runtime_error(msg);
30+
}
31+
32+
void case1()
33+
try
34+
{
35+
raise("error occured");
36+
}
37+
catch(const exception& e)
38+
{
39+
cout << e.what() << endl;
40+
}
41+
42+
int main()
43+
{
44+
case1();
45+
46+
cout << "exception demo" << endl;
47+
}

0 commit comments

Comments
 (0)