feat: add source_location to (syntax_|type_)error

This commit is contained in:
ToruNiina
2019-10-31 22:04:16 +09:00
parent 56812114c3
commit 8e589ff4d7

View File

@@ -2,6 +2,7 @@
// Distributed under the MIT License. // Distributed under the MIT License.
#ifndef TOML11_EXCEPTION_HPP #ifndef TOML11_EXCEPTION_HPP
#define TOML11_EXCEPTION_HPP #define TOML11_EXCEPTION_HPP
#include "source_location.hpp"
#include <stdexcept> #include <stdexcept>
#include <string> #include <string>
@@ -18,32 +19,41 @@ struct exception : public std::exception
struct syntax_error : public toml::exception struct syntax_error : public toml::exception
{ {
public: public:
explicit syntax_error(const std::string& what_arg) : what_(what_arg){} explicit syntax_error(const std::string& what_arg, const source_location& loc)
explicit syntax_error(const char* what_arg) : what_(what_arg){} : what_(what_arg), loc_(loc)
{}
virtual ~syntax_error() noexcept override = default; virtual ~syntax_error() noexcept override = default;
virtual const char* what() const noexcept override {return what_.c_str();} virtual const char* what() const noexcept override {return what_.c_str();}
source_location const& location() const noexcept {return loc_;}
protected: protected:
std::string what_; std::string what_;
source_location loc_;
}; };
struct type_error : public toml::exception struct type_error : public toml::exception
{ {
public: public:
explicit type_error(const std::string& what_arg) : what_(what_arg){} explicit type_error(const std::string& what_arg, const source_location& loc)
explicit type_error(const char* what_arg) : what_(what_arg){} : what_(what_arg), loc_(loc)
{}
virtual ~type_error() noexcept override = default; virtual ~type_error() noexcept override = default;
virtual const char* what() const noexcept override {return what_.c_str();} virtual const char* what() const noexcept override {return what_.c_str();}
source_location const& location() const noexcept {return loc_;}
protected: protected:
std::string what_; std::string what_;
source_location loc_;
}; };
struct internal_error : public toml::exception struct internal_error : public toml::exception
{ {
public: public:
explicit internal_error(const std::string& what_arg) : what_(what_arg){} explicit internal_error(const std::string& what_arg)
explicit internal_error(const char* what_arg) : what_(what_arg){} : what_(what_arg)
{}
virtual ~internal_error() noexcept override = default; virtual ~internal_error() noexcept override = default;
virtual const char* what() const noexcept override {return what_.c_str();} virtual const char* what() const noexcept override {return what_.c_str();}
protected: protected: