-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathexceptions.hpp
65 lines (54 loc) · 1.47 KB
/
exceptions.hpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
#ifndef SJTU_EXCEPTIONS_HPP
#define SJTU_EXCEPTIONS_HPP
#include <cstddef>
#include <cstring>
#include <string>
namespace sjtu
{
class exception
{
protected:
const std::string variant = "";
std::string detail = "";
public:
exception() {}
exception(const exception &ec) : variant(ec.variant), detail(ec.detail){}
virtual std::string what()
{
return variant + " " + detail;
}
};
class index_out_of_bound : public exception
{
protected:
const std::string variant;
public:
index_out_of_bound(const std::string &ec = std :: string("")) : variant(ec) { detail = "error : index out of bound.";}
virtual std::string what() { return variant + " " + detail;}
};
class runtime_error : public exception
{
protected:
const std::string variant;
public:
runtime_error(const std::string &ec = std :: string("")) : variant(ec) { detail = "error : runtime error.";}
virtual std::string what() { return variant + " " + detail;}
};
class invalid_iterator : public exception
{
protected:
const std::string variant;
public:
invalid_iterator(const std::string &ec = std :: string("")) : variant(ec) { detail = "error : invalid iterator.";}
virtual std::string what() { return variant + " " + detail;}
};
class container_is_empty : public exception
{
protected:
const std::string variant;
public:
container_is_empty(const std::string &ec = std :: string("")) : variant(ec) { detail = "error : container is empty.";}
virtual std::string what() { return variant + " " + detail;}
};
}
#endif