exceptions.hpp 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104
  1. // ----------------------------------------------------------------------------
  2. // boost/format/exceptions.hpp
  3. // ----------------------------------------------------------------------------
  4. // Copyright Samuel Krempp 2003.
  5. //
  6. // Distributed under the Boost Software License, Version 1.0.
  7. // (See accompanying file LICENSE_1_0.txt or copy at
  8. // http://www.boost.org/LICENSE_1_0.txt)
  9. //
  10. //
  11. // See http://www.boost.org/libs/format/ for library home page
  12. // ----------------------------------------------------------------------------
  13. #ifndef BOOST_FORMAT_EXCEPTIONS_HPP
  14. #define BOOST_FORMAT_EXCEPTIONS_HPP
  15. #include <boost/config.hpp>
  16. #include <stdexcept>
  17. namespace boost {
  18. namespace io {
  19. // **** exceptions -----------------------------------------------
  20. class format_error : public std::exception
  21. {
  22. public:
  23. format_error() {}
  24. virtual const char *what() const BOOST_NOEXCEPT_OR_NOTHROW BOOST_OVERRIDE {
  25. return "boost::format_error: "
  26. "format generic failure";
  27. }
  28. };
  29. class bad_format_string : public format_error
  30. {
  31. std::size_t pos_, next_;
  32. public:
  33. bad_format_string(std::size_t pos, std::size_t size)
  34. : pos_(pos), next_(size) {}
  35. std::size_t get_pos() const { return pos_; }
  36. std::size_t get_next() const { return next_; }
  37. virtual const char *what() const BOOST_NOEXCEPT_OR_NOTHROW BOOST_OVERRIDE {
  38. return "boost::bad_format_string: format-string is ill-formed";
  39. }
  40. };
  41. class too_few_args : public format_error
  42. {
  43. std::size_t cur_, expected_;
  44. public:
  45. too_few_args(std::size_t cur, std::size_t expected)
  46. : cur_(cur), expected_(expected) {}
  47. std::size_t get_cur() const { return cur_; }
  48. std::size_t get_expected() const { return expected_; }
  49. virtual const char *what() const BOOST_NOEXCEPT_OR_NOTHROW BOOST_OVERRIDE {
  50. return "boost::too_few_args: "
  51. "format-string referred to more arguments than were passed";
  52. }
  53. };
  54. class too_many_args : public format_error
  55. {
  56. std::size_t cur_, expected_;
  57. public:
  58. too_many_args(std::size_t cur, std::size_t expected)
  59. : cur_(cur), expected_(expected) {}
  60. std::size_t get_cur() const { return cur_; }
  61. std::size_t get_expected() const { return expected_; }
  62. virtual const char *what() const BOOST_NOEXCEPT_OR_NOTHROW BOOST_OVERRIDE {
  63. return "boost::too_many_args: "
  64. "format-string referred to fewer arguments than were passed";
  65. }
  66. };
  67. class out_of_range : public format_error
  68. {
  69. int index_, beg_, end_; // range is [ beg, end [
  70. public:
  71. out_of_range(int index, int beg, int end)
  72. : index_(index), beg_(beg), end_(end) {}
  73. int get_index() const { return index_; }
  74. int get_beg() const { return beg_; }
  75. int get_end() const { return end_; }
  76. virtual const char *what() const BOOST_NOEXCEPT_OR_NOTHROW BOOST_OVERRIDE {
  77. return "boost::out_of_range: "
  78. "tried to refer to an argument (or item) number which"
  79. " is out of range, according to the format string";
  80. }
  81. };
  82. } // namespace io
  83. } // namespace boost
  84. #endif // BOOST_FORMAT_EXCEPTIONS_HPP