1 // 2 // PostgreSQLException.h 3 // 4 // Library: Data/PostgreSQL 5 // Package: PostgreSQL 6 // Module: PostgreSQLException 7 // 8 // Definition of the PostgreSQLException class. 9 // 10 // Copyright (c) 2015, Applied Informatics Software Engineering GmbH. 11 // and Contributors. 12 // 13 // SPDX-License-Identifier: BSL-1.0 14 // 15 16 17 #ifndef SQL_PostgreSQL_PostgreSQLException_INCLUDED 18 #define SQL_PostgreSQL_PostgreSQLException_INCLUDED 19 20 21 #include "Poco/Data/PostgreSQL/PostgreSQL.h" 22 #include "Poco/Data/DataException.h" 23 #include <typeinfo> 24 #include <string> 25 26 27 namespace Poco { 28 namespace Data { 29 namespace PostgreSQL { 30 31 32 class PostgreSQL_API PostgreSQLException: public Poco::Data::DataException 33 /// Base class for all PostgreSQL exceptions 34 { 35 public: 36 explicit PostgreSQLException(const std::string& aMessage); 37 /// Creates PostgreSQLException. 38 39 PostgreSQLException(const PostgreSQLException& exc); 40 /// Creates PostgreSQLException. 41 42 ~PostgreSQLException() noexcept; 43 /// Destroys PostgreSQLexception. 44 45 PostgreSQLException& operator = (const PostgreSQLException& exc); 46 /// Assignment operator. 47 48 const char* name() const noexcept; 49 /// Returns exception name. 50 51 const char* className() const noexcept; 52 /// Returns the name of the exception class. 53 54 Poco::Exception* clone() const; 55 /// Creates an exact copy of the exception. 56 /// 57 /// The copy can later be thrown again by 58 /// invoking rethrow() on it. 59 60 void rethrow() const; 61 /// (Re)Throws the exception. 62 /// 63 /// This is useful for temporarily storing a 64 /// copy of an exception (see clone()), then 65 /// throwing it again. 66 }; 67 68 69 class ConnectionException: public PostgreSQLException 70 /// ConnectionException 71 { 72 public: 73 ConnectionException(const std::string& aMessage); 74 /// Creates ConnectionException from string. 75 }; 76 77 78 class TransactionException: public ConnectionException 79 /// TrabsactionException 80 { 81 public: 82 TransactionException(const std::string& aMessage); 83 /// Creates TransactionException from string. 84 }; 85 86 87 class StatementException: public PostgreSQLException 88 /// StatementException 89 { 90 public: 91 StatementException(const std::string& aMessage); 92 /// Creates StatementException from string. 93 }; 94 95 96 // 97 // inlines 98 // 99 100 101 inline PostgreSQLException& PostgreSQLException::operator = (const PostgreSQLException& exc) 102 { 103 Poco::Data::DataException::operator = (exc); 104 return *this; 105 } 106 107 name()108inline const char* PostgreSQLException::name() const noexcept 109 { 110 return "PostgreSQL"; 111 } 112 113 className()114inline const char* PostgreSQLException::className() const noexcept 115 { 116 return typeid(*this).name(); 117 } 118 119 clone()120inline Poco::Exception* PostgreSQLException::clone() const 121 { 122 return new PostgreSQLException(*this); 123 } 124 125 rethrow()126inline void PostgreSQLException::rethrow() const 127 { 128 throw *this; 129 } 130 131 132 } } } // namespace Poco::Data::PostgreSQL 133 134 135 #endif //SQL_PostgreSQL_PostgreSQLException_INCLUDED 136