gVirtualXRay  2.0.10
VirtualX-RayImagingLibraryonGPU
Exception.inl
Go to the documentation of this file.
1 /*
2 
3 Copyright (c) 2014, Dr Franck P. Vidal (franck.p.vidal@fpvidal.net),
4 http://www.fpvidal.net/
5 All rights reserved.
6 
7 Redistribution and use in source and binary forms, with or without modification,
8 are permitted provided that the following conditions are met:
9 
10 1. Redistributions of source code must retain the above copyright notice,
11 this list of conditions and the following disclaimer.
12 
13 2. Redistributions in binary form must reproduce the above copyright notice,
14 this list of conditions and the following disclaimer in the documentation and/or
15 other materials provided with the distribution.
16 
17 3. Neither the name of the Bangor University nor the names of its contributors
18 may be used to endorse or promote products derived from this software without
19 specific prior written permission.
20 
21 THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
22 ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
23 THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
24 ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
25 FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
26 DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
27 SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
28 CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
29 OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
30 THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
31 
32 */
33 
34 
62 //******************************************************************************
63 // Include
64 //******************************************************************************
65 #include <sstream>
66 
67 
68 //******************************************************************************
69 // define
70 //******************************************************************************
71 
72 
73 //******************************************************************************
74 // namespace
75 //******************************************************************************
76 namespace gVirtualXRay {
77 
78 
79 //-----------------------------------------------------------
80 inline std::ostream& operator<<(std::ostream& anOutputStream,
81  const Exception& anException)
82 //-----------------------------------------------------------
83 {
84  anOutputStream << anException.what();
85 
86  return (anOutputStream);
87 }
88 
89 
90 //------------------------------------------------------
91 inline Exception::Exception(const char* aFileName,
92  const char* aFunctionName,
93  int anErrorLine,
94  const char* anErrorMessage):
95 //------------------------------------------------------
96  std::exception()
97 //------------------------------------------------------
98 {
99  std::stringstream error_message;
100 
101  if (anErrorMessage)
102  {
103  error_message << "Error: " << anErrorMessage << std::endl;
104  }
105  else
106  {
107  error_message << "Error: " << std::endl;
108  }
109  error_message << "\t- in File: " << aFileName << std::endl;
110  error_message << "\t- in Function: " << aFunctionName << std::endl;
111  error_message << "\t- at Line: " << anErrorLine << std::endl;
112 
113  m_error_message = error_message.str();
114 }
115 
116 
117 //-------------------------------------------------------------
118 inline Exception::Exception(const char* aFileName,
119  const char* aFunctionName,
120  int anErrorLine,
121  const std::string& anErrorMessage):
122 //-------------------------------------------------------------
123  std::exception()
124 //-------------------------------------------------------------
125 {
126  std::stringstream error_message;
127  error_message << "Error: " << anErrorMessage << std::endl;
128  error_message << "\t- in File: " << aFileName << std::endl;
129  error_message << "\t- in Function: " << aFunctionName << std::endl;
130  error_message << "\t- at Line: " << anErrorLine << std::endl;
131 
132  m_error_message = error_message.str();
133 }
134 
135 
136 //------------------------------------
137 inline Exception::~Exception() throw()
138 //------------------------------------
139 {}
140 
141 
142 //------------------------------------------------
143 inline const char* Exception::what() const throw()
144 //------------------------------------------------
145 {
146  return (m_error_message.data());
147 }
148 
149 
150 } // namespace gVirtualXRay
std::string m_error_message
The error message.
Definition: Exception.h:168
STL namespace.
Exception(const char *aFileName=0, const char *aFunctionName=0, int anErrorLine=0, const char *anErrorMessage=0)
Default constructor.
Definition: Exception.inl:91
Exception is a class to handle exceptions.
Definition: Exception.h:109
std::ostream & operator<<(std::ostream &anOutputSream, const gVirtualXRay::AtomicElement &anElement)
operator <<
virtual const char * what() const
Accessor on the error message.
Definition: Exception.inl:143
virtual ~Exception()
Destructor.
Definition: Exception.inl:137