fw4spl
Main Page
Related Pages
Modules
Namespaces
Classes
Files
File List
File Members
exceptionmacros.hpp
1
/* ***** BEGIN LICENSE BLOCK *****
2
* FW4SPL - Copyright (C) IRCAD, 2009-2015.
3
* Distributed under the terms of the GNU Lesser General Public License (LGPL) as
4
* published by the Free Software Foundation.
5
* ****** END LICENSE BLOCK ****** */
6
7
#ifndef __FWCORE_EXCEPTIONMACROS_HPP__
8
#define __FWCORE_EXCEPTIONMACROS_HPP__
9
10
# include <boost/exception/exception.hpp>
11
# include <boost/throw_exception.hpp>
12
13
# include "fwCore/Exception.hpp"
14
# include "
fwCore/spyLog.hpp
"
15
# include "fwCore/Demangler.hpp"
16
17
# define LOG_FWEXCEPTIONS 1
18
19
# define __FWCORE_EXCEPTION_CLASS ::fwCore::Exception
20
21
# define __FWCORE_EXCEPTION_PREPARE_MSG(var, msg) \
22
std::stringstream var; \
23
var << msg
24
25
# define __FWCORE_EXCEPTION_GETCLASSNAME(obj) \
26
::fwCore::Demangler(typeid(obj)).getClassname()
27
28
# define __FWCORE_EXCEPTION_INFO(excep) \
29
"Exception: <" \
30
<< __FWCORE_EXCEPTION_GETCLASSNAME(excep) \
31
<< ">: " << excep.what()
32
33
// --------------------------------------------------------------------------------
34
35
# ifdef LOG_FWEXCEPTIONS
36
# define __FWCORE_EXCEPTION_LOG(excep) \
37
OSLM_WARN(__FWCORE_EXCEPTION_INFO(excep))
38
# else
39
# define __FWCORE_EXCEPTION_LOG(excep)
40
# endif
41
42
// --------------------------------------------------------------------------------
43
44
# define __FWCORE_EXCEPT_RAISE_EXCEPTION(excep) \
45
__FWCORE_EXCEPTION_LOG(excep); \
46
BOOST_THROW_EXCEPTION(excep)
47
48
# define __FWCORE_EXCEPT_RAISE_EXCEPTION_MSG(excep_class, msg) \
49
__FWCORE_EXCEPTION_PREPARE_MSG(_fwcore_exception_msgstream, msg); \
50
__FWCORE_EXCEPT_RAISE_EXCEPTION( \
51
excep_class(_fwcore_exception_msgstream.str()))
52
53
# define __FWCORE_EXCEPT_RAISE(msg) \
54
__FWCORE_EXCEPT_RAISE_EXCEPTION_MSG(__FWCORE_EXCEPTION_CLASS, msg)
55
56
# define __FWCORE_EXCEPT_RAISE_EXCEPTION_IF(excep, cond) \
57
__FWCORE_IF(cond, __FWCORE_EXCEPT_RAISE_EXCEPTION(excep); )
58
59
# define __FWCORE_EXCEPT_RAISE_IF(msg, cond) \
60
__FWCORE_IF(cond, __FWCORE_EXCEPT_RAISE(msg); )
61
62
# define __FWCORE_EXCEPT_FORWARD_EXCEPTION(excep) \
63
BOOST_THROW_EXCEPTION(excep)
64
65
# define __FWCORE_EXCEPT_FORWARD_EXCEPTION_IF(excep, cond) \
66
__FWCORE_IF(cond, BOOST_THROW_EXCEPTION(excep); )
67
68
// -----------------------------------------------------------------------------
69
70
# ifdef FWEXCEPTIONS_AS_ASSERTS
71
72
# undef __FWCORE_EXCEPT_RAISE_EXCEPTION
73
# define __FWCORE_EXCEPT_RAISE_EXCEPTION(excep) \
74
OSLM_ASSERT(__FWCORE_EXCEPTION_INFO(excep), false)
75
76
# undef __FWCORE_EXCEPT_FORWARD_EXCEPTION
77
# define __FWCORE_EXCEPT_FORWARD_EXCEPTION(excep) \
78
OSLM_ASSERT( \
79
"[Forwarded] " << __FWCORE_EXCEPTION_INFO (excep), \
80
false)
81
82
# undef __FWCORE_EXCEPT_FORWARD_EXCEPTION_IF
83
# define __FWCORE_EXCEPT_FORWARD_EXCEPTION_IF(excep, cond) \
84
OSLM_ASSERT( \
85
"[Forwarded] " << __FWCORE_EXCEPTION_INFO (excep), \
86
cond)
87
88
# endif
89
90
// -----------------------------------------------------------------------------
91
92
# define FW_RAISE_EXCEPTION(excep) __FWCORE_EXPR_BLOCK( \
93
__FWCORE_EXCEPT_RAISE_EXCEPTION(excep); \
94
)
95
96
# define FW_RAISE_EXCEPTION_MSG(excep_class, msg) __FWCORE_EXPR_BLOCK( \
97
__FWCORE_EXCEPT_RAISE_EXCEPTION_MSG(excep_class, msg); \
98
)
99
100
# define FW_RAISE(msg) __FWCORE_EXPR_BLOCK( \
101
__FWCORE_EXCEPT_RAISE(msg); \
102
)
103
104
# define FW_RAISE_EXCEPTION_IF(excep, cond) __FWCORE_EXPR_BLOCK( \
105
__FWCORE_EXCEPT_RAISE_EXCEPTION_IF(excep, cond) \
106
)
107
108
# define FW_RAISE_IF(msg, cond) __FWCORE_EXPR_BLOCK( \
109
__FWCORE_EXCEPT_RAISE_IF(msg, cond) \
110
)
111
112
# define FW_FORWARD_EXCEPTION(excep) __FWCORE_EXPR_BLOCK( \
113
__FWCORE_EXCEPT_FORWARD_EXCEPTION(excep); \
114
)
115
116
# define FW_FORWARD_EXCEPTION_IF(excep, cond) __FWCORE_EXPR_BLOCK( \
117
__FWCORE_EXCEPT_FORWARD_EXCEPTION_IF(excep, cond); \
118
)
119
120
#endif // __FWCORE_EXCEPTIONMACROS_HPP__
spyLog.hpp
This file defines SpyLog macros. These macros are used to log messages to a file or to the console du...
SrcLib
core
fwCore
include
fwCore
exceptionmacros.hpp
Generated on Wed Sep 5 2018 12:47:40 for fw4spl by
1.8.11