CARMA C++
BaseException.h
Go to the documentation of this file.
1 #ifndef CARMA_UTIL_BASE_EXCEPTION_H
2 #define CARMA_UTIL_BASE_EXCEPTION_H
3 
26 #include <exception>
27 #include <string>
28 #include <iosfwd>
29 #include <vector>
30 #include <memory>
31 #include <cstdlib>
32 #include <cstring>
33 
34 #include <log4cpp/Priority.hh>
35 
36 #include "carma/util/Backtrace.h"
37 
38 
39 namespace carma {
40 namespace util {
41 
48 class BaseException : public ::std::exception {
49  public:
53  virtual ~BaseException( ) throw( );
54 
67  virtual const char * what( ) const throw( );
68 
80  virtual void setMessageDirectly( const char * mesg );
81 
82  virtual void setMessageToCopy( const char * mesg );
83 
93  virtual void setMessageToCopy( const ::std::string & mesg );
94 
104  virtual void setMessageToCopy( const ::std::ostringstream & oss );
105 
114  virtual const char * getMessage( ) const;
115 
125  virtual const char * getSourceFile( ) const;
126 
136  virtual int getLineNumber( ) const;
137 
138 
139  virtual ::std::string getLogString( ) const;
140 
152  void logException( log4cpp::Priority::PriorityLevel priority ) const;
153 
154  Backtrace getBacktrace( ) const;
155 
156  protected:
157  explicit BaseException( );
158 
159  BaseException( const BaseException & rhs );
160 
181  BaseException( const char * mesg,
182  const char * fileName,
183  const int lineNo );
184 
185  BaseException( const char * mesg,
186  const ::std::string & fileName,
187  const int lineNo );
188 
189  BaseException( const ::std::string & mesg,
190  const char * fileName,
191  const int lineNo );
192 
193  BaseException( const ::std::string & mesg,
194  const ::std::string & fileName,
195  const int lineNo );
196 
197  BaseException( const ::std::ostringstream & oss,
198  const char * fileName,
199  const int lineNo );
200 
201  BaseException( const ::std::ostringstream & oss,
202  const ::std::string & fileName,
203  const int lineNo );
204 
205  BaseException & operator=( const BaseException & rhs );
206 
215  virtual void setLineNumber( int num );
216 
226  void setSourceFileDirectly( const char * file );
227 
228  void setSourceFileToCopy( const char * file );
229  void setSourceFileToCopy( const ::std::string & file );
230 
231  private:
232  void clearMesg( );
233  void clearSourceFile( );
234 
235  void swap( BaseException & rhs );
236 
237  const char * mesg_;
238  bool weAllocatedMesg_;
239  const char * sourceFile_;
240  bool weAllocatedSourceFile_;
241  int lineNo_;
242  Backtrace backtrace_;
243 }; // class BaseException
244 
245 
246 } // namespace carma::util
247 } // namespace carma
248 
249 
258 #define CARMA_EXCEPTION(x,y) x((y), __FILE__, __LINE__)
259 
268 #define CARMA_TEST( e, ce, m ) \
269 do { \
270  if ( ! (e) ) \
271  { \
272  ::std::ostringstream os; \
273  os << "CARMA_TEST FAIL: " << m; \
274  ce error( os, __FILE__, __LINE__); \
275  error.logException(::log4cpp::Priority::ERROR); \
276  throw error; \
277  } \
278 } while (false)
279 
280 #endif // CARMA_UTIL_BASE_EXCEPTION_H
281 
282 
virtual const char * getMessage() const
virtual void setLineNumber(int num)
virtual int getLineNumber() const
void logException(log4cpp::Priority::PriorityLevel priority) const
virtual const char * what() const
void setSourceFileDirectly(const char *file)
Interface file for the carma::util::Backtrace class.
Base exception class for managing carma errors.
Definition: BaseException.h:48
Class to hold a captured call stack backtrace.
Definition: Backtrace.h:16
virtual void setMessageDirectly(const char *mesg)
virtual const char * getSourceFile() const