| 1 | // ---------------------------------------------------------------------------- |
| 2 | // Copyright (C) 2002-2006 Marcin Kalicinski |
| 3 | // Copyright (C) 2009 Sebastian Redl |
| 4 | // |
| 5 | // Distributed under the Boost Software License, Version 1.0. |
| 6 | // (See accompanying file LICENSE_1_0.txt or copy at |
| 7 | // http://www.boost.org/LICENSE_1_0.txt) |
| 8 | // |
| 9 | // For more information, see www.boost.org |
| 10 | // ---------------------------------------------------------------------------- |
| 11 | |
| 12 | #ifndef BOOST_PROPERTY_TREE_EXCEPTIONS_HPP_INCLUDED |
| 13 | #define BOOST_PROPERTY_TREE_EXCEPTIONS_HPP_INCLUDED |
| 14 | |
| 15 | #include <boost/property_tree/ptree_fwd.hpp> |
| 16 | |
| 17 | #include <boost/any.hpp> |
| 18 | #include <stdexcept> |
| 19 | #include <string> |
| 20 | |
| 21 | namespace boost { namespace property_tree |
| 22 | { |
| 23 | |
| 24 | /// Base class for all property tree errors. Derives from |
| 25 | /// @c std::runtime_error. Call member function @c what to get human |
| 26 | /// readable message associated with the error. |
| 27 | class ptree_error : public std::runtime_error |
| 28 | { |
| 29 | public: |
| 30 | /// Instantiate a ptree_error instance with the given message. |
| 31 | /// @param what The message to associate with this error. |
| 32 | ptree_error(const std::string &what); |
| 33 | }; |
| 34 | |
| 35 | |
| 36 | /// Error indicating that translation from given value to the property tree |
| 37 | /// data_type (or vice versa) failed. Derives from ptree_error. |
| 38 | class ptree_bad_data : public ptree_error |
| 39 | { |
| 40 | public: |
| 41 | /// Instantiate a ptree_bad_data instance with the given message and |
| 42 | /// data. |
| 43 | /// @param what The message to associate with this error. |
| 44 | /// @param data The value associated with this error that was the source |
| 45 | /// of the translation failure. |
| 46 | template<class T> ptree_bad_data(const std::string &what, |
| 47 | const T &data); |
| 48 | |
| 49 | /// Retrieve the data associated with this error. This is the source |
| 50 | /// value that failed to be translated. You need to explicitly |
| 51 | /// specify its type. |
| 52 | template<class T> T data() const; |
| 53 | private: |
| 54 | boost::any m_data; |
| 55 | }; |
| 56 | |
| 57 | |
| 58 | /// Error indicating that specified path does not exist. Derives from |
| 59 | /// ptree_error. |
| 60 | class ptree_bad_path : public ptree_error |
| 61 | { |
| 62 | public: |
| 63 | /// Instantiate a ptree_bad_path with the given message and path data. |
| 64 | /// @param what The message to associate with this error. |
| 65 | /// @param path The path that could not be found in the property_tree. |
| 66 | template<class T> ptree_bad_path(const std::string &what, |
| 67 | const T &path); |
| 68 | |
| 69 | /// Retrieve the invalid path. You need to explicitly specify the |
| 70 | /// type of path. |
| 71 | template<class T> T path() const; |
| 72 | private: |
| 73 | boost::any m_path; |
| 74 | }; |
| 75 | |
| 76 | }} |
| 77 | |
| 78 | #include <boost/property_tree/detail/exception_implementation.hpp> |
| 79 | |
| 80 | #endif |
| 81 | |