-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathExceptions.hpp
More file actions
97 lines (77 loc) · 1.9 KB
/
Exceptions.hpp
File metadata and controls
97 lines (77 loc) · 1.9 KB
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
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
#ifndef __EXCEPTIONS__
#define __EXCEPTIONS__
#include <ostream>
#include <string>
#include <typeinfo>
// errors basic messages
#define TYPE_ERR_MSG "TypeError: "
#define PARAM_ERR_MSG "Parameter error: "
#define SOCK_ERR_MSG "Sockets: "
#define FILE_ERR_MSG "FileError: "
#define SIZE_ERR_MSG "SizeError: "
//------------------------------
// base class
class ExceptionBase
{
public:
virtual ~ExceptionBase();
virtual void print(std::ostream &out) const = 0;
virtual std::string get_msg() const = 0;
friend std::ostream &operator<< (std::ostream &out, const ExceptionBase &exc);
};
//------------------------------
class TypeError : public ExceptionBase
{
public:
TypeError(const std::string &msg_src);
void print(std::ostream &out) const;
std::string get_msg() const;
private:
std::string msg;
};
//------------------------------
template <typename ParamType>
class ParameterError : public ExceptionBase
{
public:
ParameterError(ParamType param_src, const std::string &msg_src);
void print(std::ostream &out) const;
std::string get_msg() const;
private:
ParamType param;
std::string msg;
};
// template class implemetation
#include "ParameterError.tpp"
//------------------------------
class SockError : public ExceptionBase
{
public:
SockError(const std::string &msg_src);
void print(std::ostream &out) const;
std::string get_msg() const;
private:
std::string msg;
};
//------------------------------
class FileError : public ExceptionBase
{
public:
FileError(const std::string &msg_src);
void print(std::ostream &out) const;
std::string get_msg() const;
private:
std::string msg;
};
//------------------------------
class SizeError : public ExceptionBase
{
public:
SizeError(size_t num_src);
void print(std::ostream &out) const;
std::string get_msg() const;
private:
size_t num;
};
//------------------------------
#endif