First public contribution.
1 // ----------------------------------------------------------------------------
2 // boost/format/exceptions.hpp
3 // ----------------------------------------------------------------------------
5 // Copyright Samuel Krempp 2003.
7 // Distributed under the Boost Software License, Version 1.0.
8 // (See accompanying file LICENSE_1_0.txt or copy at
9 // http://www.boost.org/LICENSE_1_0.txt)
12 // See http://www.boost.org/libs/format/ for library home page
14 // ----------------------------------------------------------------------------
16 #ifndef BOOST_FORMAT_EXCEPTIONS_HPP
17 #define BOOST_FORMAT_EXCEPTIONS_HPP
27 // **** exceptions -----------------------------------------------
29 class format_error : public std::exception
33 virtual const char *what() const throw() {
34 return "boost::format_error: "
35 "format generic failure";
39 class bad_format_string : public format_error
41 std::size_t pos_, next_;
43 bad_format_string(std::size_t pos, std::size_t size)
44 : pos_(pos), next_(size) {}
45 std::size_t get_pos() const { return pos_; }
46 std::size_t get_next() const { return next_; }
47 virtual const char *what() const throw() {
48 return "boost::bad_format_string: format-string is ill-formed";
52 class too_few_args : public format_error
54 std::size_t cur_, expected_;
56 too_few_args(std::size_t cur, std::size_t expected)
57 : cur_(cur), expected_(expected) {}
58 std::size_t get_cur() const { return cur_; }
59 std::size_t get_expected() const { return expected_; }
60 virtual const char *what() const throw() {
61 return "boost::too_few_args: "
62 "format-string referred to more arguments than were passed";
66 class too_many_args : public format_error
68 std::size_t cur_, expected_;
70 too_many_args(std::size_t cur, std::size_t expected)
71 : cur_(cur), expected_(expected) {}
72 std::size_t get_cur() const { return cur_; }
73 std::size_t get_expected() const { return expected_; }
74 virtual const char *what() const throw() {
75 return "boost::too_many_args: "
76 "format-string referred to less arguments than were passed";
81 class out_of_range : public format_error
83 int index_, beg_, end_; // range is [ beg, end [
85 out_of_range(int index, int beg, int end)
86 : index_(index), beg_(beg), end_(end) {}
87 int get_index() const { return index_; }
88 int get_beg() const { return beg_; }
89 int get_end() const { return end_; }
90 virtual const char *what() const throw() {
91 return "boost::out_of_range: "
92 "tried to refer to an argument (or item) number which"
93 " is out of range, according to the format string";
103 #endif // BOOST_FORMAT_EXCEPTIONS_HPP