feat: add src_loc to all the exceptions

including internal_error.
This commit is contained in:
ToruNiina
2019-11-01 21:14:33 +09:00
parent 6862264bde
commit bc3eb9d967
2 changed files with 73 additions and 42 deletions

View File

@@ -12,50 +12,50 @@ namespace toml
struct exception : public std::exception
{
public:
exception(const source_location& loc): loc_(loc) {}
virtual ~exception() noexcept override = default;
virtual const char* what() const noexcept override {return "";}
virtual source_location const& location() const noexcept {return loc_;}
protected:
source_location loc_;
};
struct syntax_error : public toml::exception
{
public:
explicit syntax_error(const std::string& what_arg, const source_location& loc)
: what_(what_arg), loc_(loc)
: exception(loc), what_(what_arg)
{}
virtual ~syntax_error() noexcept override = default;
virtual const char* what() const noexcept override {return what_.c_str();}
source_location const& location() const noexcept {return loc_;}
protected:
std::string what_;
source_location loc_;
};
struct type_error : public toml::exception
{
public:
explicit type_error(const std::string& what_arg, const source_location& loc)
: what_(what_arg), loc_(loc)
: exception(loc), what_(what_arg)
{}
virtual ~type_error() noexcept override = default;
virtual const char* what() const noexcept override {return what_.c_str();}
source_location const& location() const noexcept {return loc_;}
protected:
std::string what_;
source_location loc_;
};
struct internal_error : public toml::exception
{
public:
explicit internal_error(const std::string& what_arg)
: what_(what_arg)
explicit internal_error(const std::string& what_arg, const source_location& loc)
: exception(loc), what_(what_arg)
{}
virtual ~internal_error() noexcept override = default;
virtual const char* what() const noexcept override {return what_.c_str();}
protected:
std::string what_;
};