From 8e589ff4d749e74f111e96e8ad9ffa2c6c17e007 Mon Sep 17 00:00:00 2001 From: ToruNiina Date: Thu, 31 Oct 2019 22:04:16 +0900 Subject: [PATCH] feat: add source_location to (syntax_|type_)error --- toml/exception.hpp | 22 ++++++++++++++++------ 1 file changed, 16 insertions(+), 6 deletions(-) diff --git a/toml/exception.hpp b/toml/exception.hpp index 1a3cd0c..08541b0 100644 --- a/toml/exception.hpp +++ b/toml/exception.hpp @@ -2,6 +2,7 @@ // Distributed under the MIT License. #ifndef TOML11_EXCEPTION_HPP #define TOML11_EXCEPTION_HPP +#include "source_location.hpp" #include #include @@ -18,32 +19,41 @@ struct exception : public std::exception struct syntax_error : public toml::exception { public: - explicit syntax_error(const std::string& what_arg) : what_(what_arg){} - explicit syntax_error(const char* what_arg) : what_(what_arg){} + explicit syntax_error(const std::string& what_arg, const source_location& loc) + : what_(what_arg), loc_(loc) + {} 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) : what_(what_arg){} - explicit type_error(const char* what_arg) : what_(what_arg){} + explicit type_error(const std::string& what_arg, const source_location& loc) + : what_(what_arg), loc_(loc) + {} 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 char* what_arg) : what_(what_arg){} + explicit internal_error(const std::string& what_arg) + : what_(what_arg) + {} virtual ~internal_error() noexcept override = default; virtual const char* what() const noexcept override {return what_.c_str();} protected: