ai-dev-template / cpp /include /utils /exceptions.hpp
Jordandevlog's picture
Upload cpp/include/utils/exceptions.hpp
3b9a06c verified
Raw
History Blame Contribute Delete
904 Bytes
/**
* @file exceptions.hpp
* @brief Custom exception hierarchy.
*/
#pragma once
#include <stdexcept>
#include <string>
namespace app::utils {
class AppException : public std::runtime_error {
public:
AppException(const std::string& msg, int code = 500)
: std::runtime_error(msg), status_code_(code) {}
int status_code() const noexcept { return status_code_; }
private:
int status_code_;
};
class ValidationError : public AppException {
public:
explicit ValidationError(const std::string& msg)
: AppException(msg, 400) {}
};
class NotFoundError : public AppException {
public:
explicit NotFoundError(const std::string& resource)
: AppException(resource + " not found", 404) {}
};
class AuthenticationError : public AppException {
public:
AuthenticationError()
: AppException("Authentication failed", 401) {}
};
} // namespace app::utils