LOOS 4.1.0
The Lightweight Object Oriented Structural analysis library/toolkit
Loading...
Searching...
No Matches
exceptions.hpp
1/*
2 This file is part of LOOS.
3
4 LOOS (Lightweight Object-Oriented Structure library)
5 Copyright (c) 2009, Tod D. Romo, Alan Grossfield
6 Department of Biochemistry and Biophysics
7 School of Medicine & Dentistry, University of Rochester
8
9 This package (LOOS) is free software: you can redistribute it and/or modify
10 it under the terms of the GNU General Public License as published by
11 the Free Software Foundation under version 3 of the License.
12
13 This package is distributed in the hope that it will be useful,
14 but WITHOUT ANY WARRANTY; without even the implied warranty of
15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 GNU General Public License for more details.
17
18 You should have received a copy of the GNU General Public License
19 along with this program. If not, see <http://www.gnu.org/licenses/>.
20*/
21
22
23#if !defined(LOOS_EXCEPTIONS_HPP)
24#define LOOS_EXCEPTIONS_HPP
25
26
27#include <sstream>
28#include <exception>
29#include <string>
30#include <loos_defs.hpp>
31
32namespace loos {
33
34
35 // Forward decl's
36 class Atom;
37 std::ostream& operator<<(std::ostream&, const Atom&);
38
40 class LOOSError : public std::exception {
41 protected:
42 std::string _msg;
43 public:
44 explicit LOOSError() : _msg("LOOS Error") { }
45 explicit LOOSError(const std::string& arg) : _msg(arg) { }
46 explicit LOOSError(const Atom& a, const std::string& arg) {
47 std::stringstream ss;
48 ss << a << std::endl << arg;
49 _msg = ss.str();
50 }
51 explicit LOOSError(const std::string& fname, const Atom& a, const std::string& arg) {
52 std::stringstream ss;
53 ss << "In file: " + fname << std::endl << a << std::endl << arg;
54 _msg = ss.str();
55 }
56
57 virtual ~LOOSError() throw() {};
58 virtual const char* what(void) const throw() { return(_msg.c_str()); }
59 };
60
62 class OptionsError : public LOOSError
63 {
64 public:
65 explicit OptionsError(const std::string& arg) : LOOSError(arg) { }
66 };
67
69 class ParseError : public LOOSError {
70 public:
71 explicit ParseError(const std::string& arg) : LOOSError(arg) { }
72 };
73
74
76 class UnsetProperty : public LOOSError {
77 public:
78 UnsetProperty() : LOOSError("Attempting to access an unset atom property") {}
79 UnsetProperty(const std::string& p) : LOOSError(p) {}
80 UnsetProperty(const Atom& a, const std::string& p) : LOOSError(a, p) {}
81 };
82
83
85
89 struct XDRDataSizeError : public LOOSError {
90 XDRDataSizeError() : LOOSError("XDR data size error") {}
91 XDRDataSizeError(const std::string& s) : LOOSError(s) {}
92 };
93
94
96 class NumericalError : public LOOSError {
97 public:
98 explicit NumericalError(const std::string& arg, const int info) {
99 std::stringstream ss;
100 ss << arg << ", info = " << info;
101 _msg = ss.str();
102 }
103 explicit NumericalError(const std::string& arg) : LOOSError(arg) { }
104 };
105
106
108
115 class FileError : public LOOSError {
116 protected:
117 std::string _operation;
118 std::string _filename;
119 int _errcode;
120
121 public:
122 FileError(const std::string& op) : LOOSError("Error while " + op), _operation(op) {}
123
124 FileError(const std::string& op, const std::string& fname)
125 : LOOSError("Error while " + op + " " + fname),
126 _operation(op), _filename(fname)
127 {}
128
129 FileError(const std::string& op,
130 const std::string& fname,
131 const std::string& msg)
132 : LOOSError("Error while " + op + " " + fname + msg),
133 _operation(op),
134 _filename(fname)
135 {}
136
137 FileError(const std::string& op,
138 const std::string& fname,
139 const std::string& msg,
140 const int err)
141 : LOOSError("Error while " + op + " " + fname + msg),
142 _operation(op),
143 _filename(fname),
144 _errcode(err)
145 {}
146
147
148
150 std::string operation() const throw() { return(_operation); }
151
153 std::string filename() const throw() { return(_filename); }
154
156 int errorCode() const { return(_errcode); }
157
159 void errorCode(const int i) { _errcode = i; }
160
161 ~FileError() throw() {}
162 };
163
165
175 class FileOpenError : public FileError {
176 public:
177 FileOpenError() : FileError("opening") { }
178 FileOpenError(const std::string& fname) : FileError("opening", fname) {}
179 FileOpenError(const std::string& fname, const std::string& msg) : FileError("opening", fname, '\n' + msg) {}
180 FileOpenError(const std::string& fname, const std::string& msg, const int err) : FileError("opening", fname, '\n' + msg, err) {}
181 };
182
183
185 class FileReadError : public FileError {
186 public:
187 FileReadError() : FileError("reading from") { }
188 FileReadError(const std::string& fname) : FileError("reading from", fname) {}
189 FileReadError(const std::string& fname, const std::string& msg) : FileError("reading from", fname, '\n' + msg) {}
190 FileReadError(const std::string& fname, const std::string& msg, const int err) : FileError("reading from", fname, '\n' + msg, err) {}
191 };
192
193
196 protected:
197 uint _lineno;
198 std::string _msg;
199 public:
200 FileReadErrorWithLine(const uint ln)
201 : FileReadError("reading"), _lineno(ln)
202 { init(); }
203
204 FileReadErrorWithLine(const std::string& fname, const uint ln)
205 : FileReadError("reading ", fname), _lineno(ln)
206 { init(); }
207
208
209 FileReadErrorWithLine(const std::string& fname, const std::string& msg, const uint ln)
210 : FileReadError("reading ", fname), _lineno(ln), _msg(msg)
211 { init(); }
212
214 uint lineNumber() const throw() { return(_lineno); }
215
216 ~FileReadErrorWithLine() throw() {}
217
218 private:
219 void init() {
220 std::ostringstream oss;
221
222 oss << FileReadError::_msg << " at line " << _lineno << std::endl << _msg;
223 FileReadError::_msg = oss.str();
224 }
225
226 };
227
228
230 class FileWriteError : public FileError {
231 public:
232 FileWriteError() : FileError("writing to") { }
233 FileWriteError(const std::string& fname) : FileError("writing to", fname) {}
234 FileWriteError(const std::string& fname, const std::string& msg) : FileError("writing to", fname, '\n' + msg) {}
235 };
236
237
239
242 class TrajectoryError : public LOOSError {
243 protected:
244 std::string _operation;
245 std::string _filename;
246 int _errcode;
247
248 public:
249 TrajectoryError(const std::string& op) : LOOSError("Error while " + op), _operation(op) {}
250
251 TrajectoryError(const std::string& op, const std::string& fname)
252 : LOOSError("Error while " + op + ", " + fname),
253 _operation(op), _filename(fname)
254 {}
255
256 TrajectoryError(const std::string& op,
257 const std::string& fname,
258 const std::string& msg)
259 : LOOSError("Error while " + op + ", " + fname + "\n" + msg),
260 _operation(op),
261 _filename(fname)
262 {}
263
264 TrajectoryError(const std::string& op,
265 const std::string& fname,
266 const std::string& msg,
267 const int err)
268 : LOOSError("Error while " + op + ", " + fname + "\n" + msg),
269 _operation(op),
270 _filename(fname),
271 _errcode(err)
272 {}
273
274
276 std::string operation() const throw() { return(_operation); }
277
279 std::string filename() const throw() { return(_filename); }
280
282 int errorCode() const { return(_errcode); }
283
285 void errorCode(const int i) { _errcode = i; }
286
287 ~TrajectoryError() throw() {}
288 };
289
290
291
292};
293
294#endif
Basic Atom class for handling atom properties.
Definition Atom.hpp:50
Errors related to File I/O.
Definition exceptions.hpp:115
void errorCode(const int i)
Sets the error code.
Definition exceptions.hpp:159
int errorCode() const
The error code that may have been generated.
Definition exceptions.hpp:156
std::string operation() const
What operation was involved (e.g. reading, writing. etc)
Definition exceptions.hpp:150
std::string filename() const
File that had the problem (or "stream" if not a file)
Definition exceptions.hpp:153
Error while opening a file.
Definition exceptions.hpp:175
Errors that occur while reading a file.
Definition exceptions.hpp:185
Errors that occur while reading a text file (where lines are tracked)
Definition exceptions.hpp:195
uint lineNumber() const
The line number that caused the problem.
Definition exceptions.hpp:214
Errors while writing to files.
Definition exceptions.hpp:230
Generic LOOS exception.
Definition exceptions.hpp:40
Exception caused by a blas/atlas error.
Definition exceptions.hpp:96
Exception in options.
Definition exceptions.hpp:63
Exception when parsing input data.
Definition exceptions.hpp:69
Errors related to trajectory reading and writing.
Definition exceptions.hpp:242
void errorCode(const int i)
Sets the error code.
Definition exceptions.hpp:285
int errorCode() const
The error code that may have been generated.
Definition exceptions.hpp:282
std::string filename() const
File that had the problem (or "stream" if not a file)
Definition exceptions.hpp:279
std::string operation() const
What operation was involved (e.g. reading, writing. etc)
Definition exceptions.hpp:276
Exception when trying to use an unset Atom property.
Definition exceptions.hpp:76
Namespace for most things not already encapsulated within a class.
Definition version.cpp:3
Exception indicating internal XDR error.
Definition exceptions.hpp:89