Skip to content
Snippets Groups Projects

Better Error Handling and Logging

Merged Timm Fitschen requested to merge dev into main
All threads resolved!
3 files
+ 16
16
Compare changes
  • Side-by-side
  • Inline
Files
3
+ 36
11
@@ -21,46 +21,71 @@
#ifndef CAOSDB_EXCEPTIONS_H
#define CAOSDB_EXCEPTIONS_H
#include "caosdb/status_code.h"
#include <stdexcept>
#include <string>
namespace caosdb::exceptions {
using caosdb::StatusCode;
using std::runtime_error;
/**
* @brief Generic exception class of the caosdb client library.
*/
class Exception : public runtime_error {
public:
explicit Exception(StatusCode code, const std::string &what_arg)
: runtime_error(what_arg), code(code) {}
[[nodiscard]] inline auto GetCode() const -> StatusCode { return this->code; }
private:
StatusCode code;
};
/**
* @brief Exception for authentication errors.
*/
class AuthenticationError : public runtime_error {
class AuthenticationError : public Exception {
public:
explicit AuthenticationError(const std::string &what_arg)
: runtime_error(what_arg) {}
: Exception(StatusCode::AUTHENTICATION_ERROR, what_arg) {}
};
/**
* @brief The connection to the CaosDB server is down.
*/
class ConnectionError : public runtime_error {
class ConnectionError : public Exception {
public:
explicit ConnectionError(const std::string &what_arg)
: runtime_error(what_arg) {}
: Exception(StatusCode::CONNECTION_ERROR, what_arg) {}
};
/**
* @brief The connection is known to the ConnectionManager under this name.
* @brief The transaction terminated unsuccessfully.
*/
class UnknownConnectionError : public runtime_error {
class TransactionError : public Exception {
public:
explicit UnknownConnectionError(const std::string &what_arg)
: runtime_error(what_arg) {}
explicit TransactionError(const std::string &what_arg)
: Exception(StatusCode::GENERIC_TRANSACTION_ERROR, what_arg) {}
};
/**
* @brief Exception for errors of the ConnectionManager.
* @brief Exception for errors of the ConfigurationManager or other components
* of the configuration.
*/
class ConfigurationError : public runtime_error {
class ConfigurationError : public Exception {
public:
explicit ConfigurationError(const std::string &what_arg)
: runtime_error(what_arg) {}
: Exception(StatusCode::CONFIGURATION_ERROR, what_arg) {}
};
/**
* @brief The connection isn't known to the ConnectionManager under this name.
*/
class UnknownConnectionError : public Exception {
public:
explicit UnknownConnectionError(const std::string &what_arg)
: Exception(StatusCode::UNKNOWN_CONNECTION_ERROR, what_arg) {}
};
} // namespace caosdb::exceptions
Loading