-
Notifications
You must be signed in to change notification settings - Fork 3
/
Exception.H
104 lines (80 loc) · 2.59 KB
/
Exception.H
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
// -*- C++ -*-
#ifndef EXPException_h
#define EXPException_h
#include <vector>
#include <string>
#include <sstream>
/** Defines an Error Handler base class EXPException to handle
exceptions
*/
class Exception : public std::exception
{
public:
//! Generic exception
explicit Exception(std::string exceptionname, std::string message,
std::string sourcefilename, int sourcelinenumber);
//! Copy constructor
Exception(const Exception& e);
//! Destructor.
virtual ~Exception() {}
//! Returns an error message suitable for printing to the user.
std::string getErrorMessage();
/** Returns a pointer to the (constant) error description.
* @return A pointer to a const char*. The underlying memory
* is in posession of the Exception object. Callers must
* not attempt to free the memory.
*/
virtual const char* what() const throw (){
return getErrorMessage().c_str();
}
protected:
//! Protected so it is only called by properly implemented classes.
Exception(string sourcefile, int linenumber);
//! Friendly name of the exception.
std::string exceptionname;
//! Error message describing the error in more detail.
std::ostringstream errormessage;
protected:
//! Source file where throw occured.
std::string sourcefilename;
//! Line number of throw.
int sourcelinenumber;
};
//! Used when execution reaches a point it should not reach.
class InternalError : public Exception
{
public:
//! Use this when you reach an unexpected state.
//@{
InternalError(std::string sourcefilename, int sourcelinenumber);
InternalError(std::string msg,
std::string sourcefilename, int sourcelinenumber);
InternalError(int err, std::string msg,
std::string sourcefilename, int sourcelinenumber);
//@}
};
//! Handles open file related exceptions.
class FileOpenException : public Exception
{
public:
//! Reports filename, errno error, and location of throw
FileOpenException(std::string filename, int errno_,
std::string sourcefilename, int sourcelinenumber);
};
//! Handle file creation related exceptions.
class FileCreateException : public Exception
{
public:
//! Reports filename, errno error, and location of throw
FileCreateException(std::string filename, int errno_,
std::string sourcefilename, int sourcelinenumber);
};
//! Handle file format related exceptions for DataStreams
class FileFormatException : public Exception
{
public:
//! Constructor: supply diagnostic message
FileFormatException(std::string message,
std::string sourcefilename, int sourcelinenumber);
};
#endif