Main Page   Namespace List   Class Hierarchy   Alphabetical List   Compound List   File List   Namespace Members   Compound Members   File Members   Related Pages  

Exception.hpp

Go to the documentation of this file.
00001 /*==========================================================================
00002  * Copyright (c) 2001 Carnegie Mellon University.  All Rights Reserved.
00003  *
00004  * Use of the Lemur Toolkit for Language Modeling and Information Retrieval
00005  * is subject to the terms of the software license set forth in the LICENSE
00006  * file included with this software, and also available at
00007  * http://www.cs.cmu.edu/~lemur/license.html
00008  *
00009  *==========================================================================
00010 */
00011 
00012 
00013 #ifndef _EXCEPTION_HPP
00014 #define _EXCEPTION_HPP
00015 
00017 
00063 #include "common_headers.hpp"
00064 
00065 typedef unsigned long LemurErrorType;
00066 
00067 class Exception {
00068 public:
00069   Exception(char *throwerString=" unknown thrower", char *whatString="unknown exception") {
00070     _what = throwerString;
00071     _what += ": ";
00072     _what += whatString;
00073   }
00074 
00075   Exception( const std::string& whoString, const std::string& whereLine, 
00076              const std::string& whatString, LemurErrorType code ) :
00077     _what( whoString + "(" + whereLine + ")" + ": " + whatString ),
00078     _code( code )
00079   {
00080   }
00081 
00082   Exception( const std::string& whoString, const std::string& whereLine,
00083              const std::string& whatString, const Exception& inner ) :
00084     _what( whoString + "(" + whereLine + ")" + ": " + whatString + "\n\t" + inner.what() ),
00085     _code(inner._code)
00086   {
00087   }
00088 
00089   ~Exception() {}
00090 
00091   inline void writeMessage(ostream &os = cerr)
00092   {
00093     os << "Exception [" << _what << "], code = " << _code << endl;
00094   }
00095 
00096   const std::string& what() const {
00097     return _what;
00098   }
00099 
00100   LemurErrorType code() const {
00101     return _code;
00102   }
00103 
00104 private:
00105   std::string _what;
00106   LemurErrorType _code;
00107 };
00108 
00109 #define LEMUR_MAKESTR(x) # x
00110 
00111 #define LEMUR_ABORT( e )                  { std::cerr << e.what() << std::endl; exit(-1); }
00112 #define LEMUR_THROW_LINE( code, text, file, line )  throw Exception( file, LEMUR_MAKESTR(line), \
00113                                                     std::string() + text, (code) )
00114 #define LEMUR_THROW(code, text)  LEMUR_THROW_LINE(code, text, __FILE__, __LINE__)
00115 #define LEMUR_RETHROW_LINE( e, text, file, line )   throw Exception( file, LEMUR_MAKESTR(line), \
00116                                                    (text), (e) )
00117 #define LEMUR_RETHROW( e, text)  LEMUR_RETHROW_LINE(e, text, __FILE__, __LINE__)
00118 
00119 #define LEMUR_GENERIC_ERROR               ((LemurErrorType)0xFFFFFFFF)
00120 #define LEMUR_MISSING_PARAMETER_ERROR     ((LemurErrorType)0xFFFFFFFE)
00121 #define LEMUR_PARSE_ERROR                 ((LemurErrorType)0xFFFFFFFD)
00122 #define LEMUR_KEYFILE_IO_ERROR            ((LemurErrorType)0xFFFFFFFC)
00123 #define LEMUR_IO_ERROR                    ((LemurErrorType)0xFFFFFFFB)
00124 #define LEMUR_RUNTIME_ERROR               ((LemurErrorType)0xFFFFFFFA)
00125 #define LEMUR_NETWORK_ERROR               ((LemurErrorType)0xFFFFFFF9)
00126 
00127 #endif

Generated on Fri Jul 2 16:25:36 2004 for Lemur Toolkit by doxygen1.2.18