Fairport
v1.0.38
|
00001 00002 00003 00004 00005 00008 00009 #ifndef FAIRPORT_UTIL_ERRORS_H 00010 #define FAIRPORT_UTIL_ERRORS_H 00011 00012 #include <stdexcept> 00013 #include "fairport/util/primitives.h" 00014 00015 namespace fairport 00016 { 00017 00020 class not_implemented : public std::logic_error 00021 { 00022 public: 00023 explicit not_implemented(const std::string& error) 00024 : logic_error(error) { } 00025 }; 00026 00029 class database_corrupt : public std::runtime_error 00030 { 00031 public: 00032 explicit database_corrupt(const std::string& error) 00033 : runtime_error(error) { } 00034 }; 00035 00038 class invalid_format : public database_corrupt 00039 { 00040 public: 00041 invalid_format() 00042 : database_corrupt("Unexpected Database Format") { } 00043 }; 00044 00047 class unexpected_page : public database_corrupt 00048 { 00049 public: 00050 explicit unexpected_page(const std::string& error) 00051 : database_corrupt(error) { } 00052 }; 00053 00056 class unexpected_block : public database_corrupt 00057 { 00058 public: 00059 explicit unexpected_block(const std::string& error) 00060 : database_corrupt(error) { } 00061 }; 00062 00065 class crc_fail : public database_corrupt 00066 { 00067 public: 00068 crc_fail(const std::string& error, ulonglong location, block_id id, ulong actual, ulong expected) 00069 : database_corrupt(error), m_location(location), m_id(id), m_actual(actual), m_expected(expected) { } 00070 private: 00071 ulonglong m_location; 00072 block_id m_id; 00073 ulong m_actual; 00074 ulong m_expected; 00075 }; 00076 00079 class sig_mismatch : public database_corrupt 00080 { 00081 public: 00082 sig_mismatch(const std::string& error, ulonglong location, block_id id, ulong actual, ulong expected) 00083 : database_corrupt(error), m_location(location), m_id(id), m_actual(actual), m_expected(expected) { } 00084 private: 00085 ulonglong m_location; 00086 block_id m_id; 00087 ulong m_actual; 00088 ulong m_expected; 00089 }; 00090 00094 template<typename K> 00095 class key_not_found : public std::exception 00096 { 00097 public: 00098 explicit key_not_found(const K& k) 00099 : m_k(k) { } 00100 virtual ~key_not_found() throw() { } 00101 00102 const char* what() const throw() 00103 { return "key not found"; } 00104 00107 const K& which() const 00108 { return m_k; } 00109 private: 00110 key_not_found<K>& operator=(const key_not_found<K>&); 00111 const K m_k; 00112 }; 00113 00114 00115 } // end namespace 00116 00117 #endif