Jpp
21.0.0-rc.1
the software that should make you happy
Loading...
Searching...
No Matches
externals
km3net-dataformat
offline
Exception.hh
Go to the documentation of this file.
1
#ifndef EXCEPTION_HH_INCLUDED
2
#define EXCEPTION_HH_INCLUDED
3
4
#include <exception>
5
#include <string>
6
#include <ostream>
7
#include <sstream>
8
#include <functional>
9
10
11
/**
12
* General exception
13
*/
14
class
Exception
:
public
std::exception {
15
public
:
16
/**
17
* Constructor.
18
*
19
* \param error error message
20
*/
21
Exception
(
const
std::string& error) :
22
std
::exception(),
23
buffer
(error)
24
{}
25
26
27
/**
28
* Destructor.
29
*/
30
~Exception
() throw()
31
{}
32
33
34
/**
35
* Get error message.
36
*
37
* \return error message
38
*/
39
virtual
const
char
*
what
()
const
throw()
40
{
41
return
buffer
.c_str();
42
}
43
44
45
/**
46
* Print error message of JException.
47
*
48
* \param out output stream
49
* \param exception exception
50
*/
51
friend
inline
std::ostream&
operator<<
(std::ostream& out,
const
Exception
& exception)
52
{
53
return
out << exception.
what
();
54
}
55
56
private
:
57
const
std::string
buffer
;
58
};
59
60
61
/**
62
* Make exception.
63
*
64
* \param JException_t exception
65
* \param A message
66
*/
67
#ifndef MAKE_EXCEPTION
68
#define MAKE_EXCEPTION(JException_t, A) std::invoke( [&]() { std::ostringstream out; out << __FILE__ << ':' << __LINE__ << std::endl << A; return JException_t(out.str()); } )
69
#endif
70
71
/**
72
* Marco for throwing exception with std::ostream compatible message.
73
*
74
* \param Exception_t exception
75
* \param A message
76
*/
77
#ifndef THROW
78
#define THROW(JException_t, A) do { throw MAKE_EXCEPTION(JException_t, A); } while(0)
79
#endif
80
81
#endif
Exception
General exception.
Definition
Exception.hh:14
Exception::~Exception
~Exception()
Destructor.
Definition
Exception.hh:30
Exception::what
virtual const char * what() const
Get error message.
Definition
Exception.hh:39
Exception::buffer
const std::string buffer
Definition
Exception.hh:57
Exception::Exception
Exception(const std::string &error)
Constructor.
Definition
Exception.hh:21
Exception::operator<<
friend std::ostream & operator<<(std::ostream &out, const Exception &exception)
Print error message of JException.
Definition
Exception.hh:51
std
Definition
JSTDTypes.hh:14
Generated by
1.12.0