File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 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+ }
You can’t perform that action at this time.
0 commit comments