exceptions.hpp 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103
  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 <stdexcept>
  16. namespace boost {
  17. namespace io {
  18. // **** exceptions -----------------------------------------------
  19. class format_error : public std::exception
  20. {
  21. public:
  22. format_error() {}
  23. virtual const char *what() const throw() {
  24. return "boost::format_error: "
  25. "format generic failure";
  26. }
  27. };
  28. class bad_format_string : public format_error
  29. {
  30. std::size_t pos_, next_;
  31. public:
  32. bad_format_string(std::size_t pos, std::size_t size)
  33. : pos_(pos), next_(size) {}
  34. std::size_t get_pos() const { return pos_; }
  35. std::size_t get_next() const { return next_; }
  36. virtual const char *what() const throw() {
  37. return "boost::bad_format_string: format-string is ill-formed";
  38. }
  39. };
  40. class too_few_args : public format_error
  41. {
  42. std::size_t cur_, expected_;
  43. public:
  44. too_few_args(std::size_t cur, std::size_t expected)
  45. : cur_(cur), expected_(expected) {}
  46. std::size_t get_cur() const { return cur_; }
  47. std::size_t get_expected() const { return expected_; }
  48. virtual const char *what() const throw() {
  49. return "boost::too_few_args: "
  50. "format-string referred to more arguments than were passed";
  51. }
  52. };
  53. class too_many_args : public format_error
  54. {
  55. std::size_t cur_, expected_;
  56. public:
  57. too_many_args(std::size_t cur, std::size_t expected)
  58. : cur_(cur), expected_(expected) {}
  59. std::size_t get_cur() const { return cur_; }
  60. std::size_t get_expected() const { return expected_; }
  61. virtual const char *what() const throw() {
  62. return "boost::too_many_args: "
  63. "format-string referred to fewer arguments than were passed";
  64. }
  65. };
  66. class out_of_range : public format_error
  67. {
  68. int index_, beg_, end_; // range is [ beg, end [
  69. public:
  70. out_of_range(int index, int beg, int end)
  71. : index_(index), beg_(beg), end_(end) {}
  72. int get_index() const { return index_; }
  73. int get_beg() const { return beg_; }
  74. int get_end() const { return end_; }
  75. virtual const char *what() const throw() {
  76. return "boost::out_of_range: "
  77. "tried to refer to an argument (or item) number which"
  78. " is out of range, according to the format string";
  79. }
  80. };
  81. } // namespace io
  82. } // namespace boost
  83. #endif // BOOST_FORMAT_EXCEPTIONS_HPP