2018-12-13 11:44:10 +00:00
|
|
|
// Copyright Toru Niina 2017.
|
|
|
|
// Distributed under the MIT License.
|
2019-03-16 05:19:47 +00:00
|
|
|
#ifndef TOML11_EXCEPTION_HPP
|
|
|
|
#define TOML11_EXCEPTION_HPP
|
2023-10-10 16:43:43 +00:00
|
|
|
|
|
|
|
#include <array>
|
2017-04-21 04:14:53 +00:00
|
|
|
#include <string>
|
2023-10-10 16:43:43 +00:00
|
|
|
#include <stdexcept>
|
|
|
|
|
2022-09-29 11:14:58 +00:00
|
|
|
#include <cstring>
|
2017-04-21 04:14:53 +00:00
|
|
|
|
2020-06-27 15:58:20 +00:00
|
|
|
#include "source_location.hpp"
|
|
|
|
|
2017-04-21 04:14:53 +00:00
|
|
|
namespace toml
|
|
|
|
{
|
|
|
|
|
2022-06-30 11:53:32 +00:00
|
|
|
struct file_io_error : public std::runtime_error
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
file_io_error(int errnum, const std::string& msg, const std::string& fname)
|
2024-01-07 01:48:17 +00:00
|
|
|
: std::runtime_error(msg + " \"" + fname + "\": errno = " + std::to_string(errnum)),
|
2022-06-30 11:53:32 +00:00
|
|
|
errno_(errnum)
|
|
|
|
{}
|
2024-01-07 01:48:17 +00:00
|
|
|
|
2022-09-29 11:14:58 +00:00
|
|
|
int get_errno() const noexcept {return errno_;}
|
|
|
|
|
2022-06-30 11:53:32 +00:00
|
|
|
private:
|
|
|
|
int errno_;
|
|
|
|
};
|
|
|
|
|
2017-04-21 04:14:53 +00:00
|
|
|
struct exception : public std::exception
|
|
|
|
{
|
|
|
|
public:
|
2020-01-19 08:51:24 +00:00
|
|
|
explicit exception(const source_location& loc): loc_(loc) {}
|
2017-06-12 13:04:59 +00:00
|
|
|
virtual ~exception() noexcept override = default;
|
2017-04-21 04:14:53 +00:00
|
|
|
virtual const char* what() const noexcept override {return "";}
|
2019-11-01 12:14:33 +00:00
|
|
|
virtual source_location const& location() const noexcept {return loc_;}
|
|
|
|
|
|
|
|
protected:
|
|
|
|
source_location loc_;
|
2017-04-21 04:14:53 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
struct syntax_error : public toml::exception
|
|
|
|
{
|
|
|
|
public:
|
2019-10-31 13:04:16 +00:00
|
|
|
explicit syntax_error(const std::string& what_arg, const source_location& loc)
|
2019-11-01 12:14:33 +00:00
|
|
|
: exception(loc), what_(what_arg)
|
2019-10-31 13:04:16 +00:00
|
|
|
{}
|
2017-06-12 13:04:59 +00:00
|
|
|
virtual ~syntax_error() noexcept override = default;
|
2017-04-21 04:14:53 +00:00
|
|
|
virtual const char* what() const noexcept override {return what_.c_str();}
|
|
|
|
|
|
|
|
protected:
|
|
|
|
std::string what_;
|
|
|
|
};
|
|
|
|
|
|
|
|
struct type_error : public toml::exception
|
|
|
|
{
|
|
|
|
public:
|
2019-10-31 13:04:16 +00:00
|
|
|
explicit type_error(const std::string& what_arg, const source_location& loc)
|
2019-11-01 12:14:33 +00:00
|
|
|
: exception(loc), what_(what_arg)
|
2019-10-31 13:04:16 +00:00
|
|
|
{}
|
2017-06-12 13:04:59 +00:00
|
|
|
virtual ~type_error() noexcept override = default;
|
2017-04-21 04:14:53 +00:00
|
|
|
virtual const char* what() const noexcept override {return what_.c_str();}
|
|
|
|
|
|
|
|
protected:
|
|
|
|
std::string what_;
|
|
|
|
};
|
|
|
|
|
|
|
|
struct internal_error : public toml::exception
|
|
|
|
{
|
|
|
|
public:
|
2019-11-01 12:14:33 +00:00
|
|
|
explicit internal_error(const std::string& what_arg, const source_location& loc)
|
|
|
|
: exception(loc), what_(what_arg)
|
2019-10-31 13:04:16 +00:00
|
|
|
{}
|
2017-06-12 13:04:59 +00:00
|
|
|
virtual ~internal_error() noexcept override = default;
|
2017-04-21 04:14:53 +00:00
|
|
|
virtual const char* what() const noexcept override {return what_.c_str();}
|
2019-11-01 12:14:33 +00:00
|
|
|
|
2017-04-21 04:14:53 +00:00
|
|
|
protected:
|
|
|
|
std::string what_;
|
|
|
|
};
|
|
|
|
|
|
|
|
} // toml
|
|
|
|
#endif // TOML_EXCEPTION
|