exceptions.hpp 2.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586
  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. #ifndef BOOST_PROPERTY_TREE_EXCEPTIONS_HPP_INCLUDED
  12. #define BOOST_PROPERTY_TREE_EXCEPTIONS_HPP_INCLUDED
  13. #include <boost/property_tree/ptree_fwd.hpp>
  14. #include <boost/any.hpp>
  15. #include <string>
  16. #include <stdexcept>
  17. namespace boost { namespace property_tree
  18. {
  19. /// Base class for all property tree errors. Derives from
  20. /// @c std::runtime_error. Call member function @c what to get human
  21. /// readable message associated with the error.
  22. class ptree_error : public std::runtime_error
  23. {
  24. public:
  25. /// Instantiate a ptree_error instance with the given message.
  26. /// @param what The message to associate with this error.
  27. ptree_error(const std::string &what);
  28. ~ptree_error() throw();
  29. };
  30. /// Error indicating that translation from given value to the property tree
  31. /// data_type (or vice versa) failed. Derives from ptree_error.
  32. class ptree_bad_data : public ptree_error
  33. {
  34. public:
  35. /// Instantiate a ptree_bad_data instance with the given message and
  36. /// data.
  37. /// @param what The message to associate with this error.
  38. /// @param data The value associated with this error that was the source
  39. /// of the translation failure.
  40. template<class T> ptree_bad_data(const std::string &what,
  41. const T &data);
  42. ~ptree_bad_data() throw();
  43. /// Retrieve the data associated with this error. This is the source
  44. /// value that failed to be translated. You need to explicitly
  45. /// specify its type.
  46. template<class T> T data() const;
  47. private:
  48. boost::any m_data;
  49. };
  50. /// Error indicating that specified path does not exist. Derives from
  51. /// ptree_error.
  52. class ptree_bad_path : public ptree_error
  53. {
  54. public:
  55. /// Instantiate a ptree_bad_path with the given message and path data.
  56. /// @param what The message to associate with this error.
  57. /// @param path The path that could not be found in the property_tree.
  58. template<class T> ptree_bad_path(const std::string &what,
  59. const T &path);
  60. ~ptree_bad_path() throw();
  61. /// Retrieve the invalid path. You need to explicitly specify the
  62. /// type of path.
  63. template<class T> T path() const;
  64. private:
  65. boost::any m_path;
  66. };
  67. }}
  68. #include <boost/property_tree/detail/exception_implementation.hpp>
  69. #endif