Skip to content

File errors.h

File List > src > errors.h

Go to the documentation of this file

/*******************************************************
 * Author: Intelligent Medical Systems
 * License: see LICENSE.md file
 *******************************************************/

#ifndef ERRORS_H
#define ERRORS_H

#include <string>

class XiLensError final : public std::exception
{
  public:
    enum class Code
    {
        None,
        FileInconsistentMetadata
    };

    explicit XiLensError(const Code code = Code::None, const std::string &message = "")
        : m_code(code), m_message(message)
    {
    }

    Code code() const
    {
        return m_code;
    }

    const std::string &message() const
    {
        return m_message;
    }

    std::string toString() const
    {
        return errorCodeToString(m_code) + " " + m_message;
    }

    static std::string errorCodeToString(const Code code)
    {
        switch (code)
        {
        case Code::FileInconsistentMetadata:
            return "File metadata is missing or has inconsistent shape.";
        default:
            return "Unknown";
        }
    }

  private:
    Code m_code;

    std::string m_message;
};
#endif // ERRORS_H