-
Notifications
You must be signed in to change notification settings - Fork 295
/
Copy pathkhmer_exception.hh
104 lines (83 loc) · 2.17 KB
/
khmer_exception.hh
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
//
// This file is part of khmer, https://github.com/dib-lab/khmer/, and is
// Copyright (C) Michigan State University, 2009-2015. It is licensed under
// the three-clause BSD license; see LICENSE.
// Contact: khmer-project@idyll.org
//
#ifndef KHMER_EXCEPTION_HH
#define KHMER_EXCEPTION_HH
#include <exception>
#include <string>
namespace khmer
{
///
// A base class for all exceptions.
//
// All exceptions should be derived from this base class or a sub-class
//
class khmer_exception : public std::exception
{
public:
explicit khmer_exception(const std::string& msg = "Generic khmer exception")
: _msg(msg) { }
virtual ~khmer_exception() throw() { }
virtual const char* what() const throw ()
{
return _msg.c_str();
}
protected:
const std::string _msg;
};
/////// Base Exceptions /////
///
// A base class for file exceptions.
//
class khmer_file_exception : public khmer_exception
{
public:
explicit khmer_file_exception(const std::string& msg)
: khmer_exception(msg) { }
};
// A base exception for value exceptions
class khmer_value_exception : public khmer_exception
{
public:
explicit khmer_value_exception(const std::string& msg)
: khmer_exception(msg) { }
};
/////// Specialised Exceptions /////
class InvalidStream : public khmer_file_exception
{
public:
InvalidStream()
: khmer_file_exception("Generic InvalidStream error") {}
InvalidStream(const std::string& msg) : khmer_file_exception(msg) {}
};
class StreamReadError : public khmer_file_exception
{
public:
StreamReadError()
: khmer_file_exception("Generic StreamReadError error") {}
StreamReadError(const std::string& msg) : khmer_file_exception(msg) {}
};
///
// An exception for invalid arguments to functions
//
class InvalidValue : public khmer_value_exception
{
public:
explicit InvalidValue(const std::string& msg)
: khmer_value_exception(msg) { }
};
///
// An exception for trying to change a read-only attributes
//
class ReadOnlyAttribute : public khmer_exception
{
public:
explicit ReadOnlyAttribute(const std::string& msg)
: khmer_exception(msg) { }
};
}
#endif // KHMER_EXCEPTION_HH
// vim: set sts=2 sw=2: