File tree 3 files changed +663
-0
lines changed
3 files changed +663
-0
lines changed Original file line number Diff line number Diff line change
1
+ #ifndef SJTU_EXCEPTIONS_HPP
2
+ #define SJTU_EXCEPTIONS_HPP
3
+
4
+ #include < cstddef>
5
+ #include < cstring>
6
+ #include < string>
7
+
8
+ namespace sjtu
9
+ {
10
+
11
+ class exception
12
+ {
13
+ protected:
14
+ const std::string variant = " " ;
15
+ std::string detail = " " ;
16
+ public:
17
+ exception () {}
18
+ exception (const exception &ec) : variant(ec.variant), detail(ec.detail){}
19
+ virtual std::string what ()
20
+ {
21
+ return variant + " " + detail;
22
+ }
23
+ };
24
+ class index_out_of_bound : public exception
25
+ {
26
+ protected:
27
+ const std::string variant;
28
+ public:
29
+ index_out_of_bound (const std::string &ec = std :: string(" " )) : variant(ec) { detail = " error : index out of bound." ;}
30
+
31
+ virtual std::string what () { return variant + " " + detail;}
32
+ };
33
+
34
+ class runtime_error : public exception
35
+ {
36
+ protected:
37
+ const std::string variant;
38
+ public:
39
+ runtime_error (const std::string &ec = std :: string(" " )) : variant(ec) { detail = " error : runtime error." ;}
40
+
41
+ virtual std::string what () { return variant + " " + detail;}
42
+ };
43
+
44
+ class invalid_iterator : public exception
45
+ {
46
+ protected:
47
+ const std::string variant;
48
+ public:
49
+ invalid_iterator (const std::string &ec = std :: string(" " )) : variant(ec) { detail = " error : invalid iterator." ;}
50
+
51
+ virtual std::string what () { return variant + " " + detail;}
52
+ };
53
+
54
+ class container_is_empty : public exception
55
+ {
56
+ protected:
57
+ const std::string variant;
58
+ public:
59
+ container_is_empty (const std::string &ec = std :: string(" " )) : variant(ec) { detail = " error : container is empty." ;}
60
+
61
+ virtual std::string what () { return variant + " " + detail;}
62
+ };
63
+ }
64
+
65
+ #endif
You can’t perform that action at this time.
0 commit comments