peary/utils/exceptions.hpp

Caribou Peary API exception classes. More…

Namespaces

Name
peary
peary::utils

Classes

Name
class peary::utils::Exception Base exception class for Peary.
class peary::utils::LogicError Exception class for logic errors.
class peary::utils::RuntimeError Exception class for runtime errors.
class peary::utils::InvalidCommandError Exception class for invalid commands.
class peary::utils::DictionnaryError Exception class for dictionary errors.
class peary::utils::InvalidArgumentError Exception class for invalid arguments.
class peary::utils::MissingImplementationError

Detailed Description

Caribou Peary API exception classes.

Copyright: Copyright (c) 2016-2025 CERN and the Peary Caribou authors. This software is distributed under the terms of the LGPL-3.0-only License, copied verbatim in the file “LICENSE.md”. SPDX-License-Identifier: LGPL-3.0-only

Source code

  
#pragma once

#include <exception>
#include <stdexcept>
#include <string>
#include <string_view>
#include <utility>

namespace peary::utils {

    class Exception : public std::exception {
    public:
        explicit Exception(std::string what_arg) : _message(std::move(what_arg)) {}

        [[nodiscard]] const char* what() const noexcept override { return _message.c_str(); }

    protected:
        Exception() = default;

        std::string _message;
    };

    class LogicError : public Exception {
    public:
        explicit LogicError(std::string what_arg) : Exception(std::move(what_arg)) {}

    protected:
        LogicError() = default;
    };

    class RuntimeError : public Exception {
    public:
        explicit RuntimeError(std::string what_arg) : Exception(std::move(what_arg)) {}

    protected:
        RuntimeError() = default;
    };

    class InvalidCommandError : public RuntimeError {
    public:
        explicit InvalidCommandError(std::string_view cmd, std::string_view reason = "") {
            _message = "Invalid command '";
            _message += cmd;
            _message += "'";
            if(!reason.empty()) {
                _message += ": ";
                _message += reason;
            }
        }
    };

    class DictionnaryError : public RuntimeError {
    public:
        explicit DictionnaryError(std::string_view name, std::string_view reason = "") {
            _message = "Error in dictionary '";
            _message += name;
            _message += "'";
            if(!reason.empty()) {
                _message += ": ";
                _message += reason;
            }
        }
    };

    class InvalidArgumentError : public LogicError {
    public:
        explicit InvalidArgumentError(std::string_view func, std::string_view reason = "") {
            _message = "Invalid argument in function '";
            _message += func;
            _message += "'";
            if(!reason.empty()) {
                _message += ": ";
                _message += reason;
            }
        }
    };

    class MissingImplementationError : public LogicError {
    public:
        explicit MissingImplementationError(std::string_view func, std::string_view reason = "") {
            _message = "Missing implementation for function '";
            _message += func;
            _message += "'";
            if(!reason.empty()) {
                _message += ": ";
                _message += reason;
            }
        }
    };

} // namespace peary::utils
  

Updated on 2025-11-14 at 11:31:23 +0100