-
Notifications
You must be signed in to change notification settings - Fork 11
/
Exceptions.hpp
184 lines (173 loc) · 6.42 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
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
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
/**
* Simple Image Processing Library
* Copyright Erik Smistad 2012
* See LICENSE file for information on use
*/
#ifndef SIPL_EXCEPTIONS
#define SIPL_EXCEPTIONS
#include <exception>
#include <stdio.h>
namespace SIPL {
class SIPLException : public std::exception {
public:
SIPLException() {
this->line = -1;
};
SIPLException(const char * message) {
this->line = -1;
this->message = message;
};
SIPLException(int line, const char * file) {
this->line = line;
this->file = file;
};
SIPLException(const char * message, int line, const char * file) {
this->message = message;
this->line = line;
this->file = file;
};
virtual const char * what() const throw() {
char * string = new char[255];
if(line > -1) {
sprintf(string, "%s \nException thrown at line %d in file %s", message, line, file);
return string;
} else {
return message;
}
};
void setLine(int line) {
this->line = line;
};
void setFile(const char * file) {
this->file = file;
};
void setMessage(const char * message) {
this->message = message;
};
private:
int line;
const char * file;
const char * message;
};
class IOException : public SIPLException {
public:
IOException() {
};
IOException(const char * filename, int line, const char * file) {
this->filename = filename;
char * message = new char[255];
sprintf(message, "IO Error with file %s", filename);
this->setMessage(message);
this->setLine(line);
this->setFile(file);
};
IOException(const char * filename) {
this->filename = filename;
char * message = new char[255];
sprintf(message, "IO Error with file %s", filename);
this->setMessage(message);
};
protected:
const char * filename;
};
class FileNotFoundException : public IOException {
public:
FileNotFoundException(const char * filename) {
this->filename = filename;
char * message = new char[255];
sprintf(message, "The following file was not found: %s", filename);
this->setMessage(message);
};
FileNotFoundException(const char * filename, int line, const char * file) {
this->filename = filename;
char * message = new char[255];
sprintf(message, "The following file was not found: %s", filename);
this->setMessage(message);
this->setLine(line);
this->setFile(file);
};
};
class OutOfBoundsException : public SIPLException {
public:
OutOfBoundsException(int x, int sizeX) {
this->x = x;
this->sizeX = sizeX;
char * message = new char[255];
sprintf(message, "Out of bounds exception. Requested position %d in image of size %d", x, sizeX);
this->setMessage(message);
};
OutOfBoundsException(int x, int sizeX, int line, const char * file) {
this->x = x;
this->sizeX = sizeX;
char * message = new char[255];
sprintf(message, "Out of bounds exception. Requested position %d in image of size %d", x, sizeX);
this->setMessage(message);
this->setLine(line);
this->setFile(file);
};
OutOfBoundsException(int x, int y, int sizeX, int sizeY) {
this->x = x;
this->y = y;
this->sizeX = sizeX;
this->sizeY = sizeY;
char * message = new char[255];
sprintf(message, "Out of bounds exception. Requested position %d, %d in image of size %d, %d", x, y, sizeX, sizeY);
this->setMessage(message);
};
OutOfBoundsException(int x, int y, int sizeX, int sizeY, int line, const char * file) {
this->x = x;
this->y = y;
this->sizeX = sizeX;
this->sizeY = sizeY;
char * message = new char[255];
sprintf(message, "Out of bounds exception. Requested position %d, %d in image of size %d, %d", x, y, sizeX, sizeY);
this->setMessage(message);
this->setLine(line);
this->setFile(file);
};
OutOfBoundsException(int x, int y, int z, int sizeX, int sizeY, int sizeZ) {
this->x = x;
this->y = y;
this->y = z;
this->sizeX = sizeX;
this->sizeY = sizeY;
this->sizeZ = sizeZ;
char * message = new char[255];
sprintf(message, "Out of bounds exception. Requested position %d, %d, %d in volume of size %d, %d, %d", x, y, z, sizeX, sizeY, sizeZ);
this->setMessage(message);
};
OutOfBoundsException(int x, int y, int z, int sizeX, int sizeY, int sizeZ, int line, const char * file) {
this->x = x;
this->y = y;
this->y = z;
this->sizeX = sizeX;
this->sizeY = sizeY;
this->sizeZ = sizeZ;
char * message = new char[255];
sprintf(message, "Out of bounds exception. Requested position %d, %d, %d in volume of size %d, %d, %d", x, y, z, sizeX, sizeY, sizeZ);
this->setMessage(message);
};
private:
int x, y, z; // position requested
int sizeX, sizeY, sizeZ;
};
class SIPLCompiledWithoutGTKException : public SIPLException {
public:
SIPLCompiledWithoutGTKException() {
this->setMessage("SIPL was compiled without GTK and cannot complete");
}
SIPLCompiledWithoutGTKException(int line, const char * file) {
this->setMessage("SIPL was compiled without GTK and cannot complete");
this->setLine(line);
this->setFile(file);
}
};
class ConversionException : public SIPLException {
public:
ConversionException() : SIPLException() {};
ConversionException(const char * message) : SIPLException(message) {};
ConversionException(int line, const char * file) : SIPLException(line, file) {};
ConversionException(const char * message, int line, const char * file) : SIPLException(message, line, file) { };
};
}; // END NAMESPACE SIPL
#endif