1 // ----------------------------------------------------------------------------
2 // boost/format/exceptions.hpp
3 // ----------------------------------------------------------------------------
5 // Copyright Samuel Krempp 2003. Use, modification, and distribution are
6 // subject to the Boost Software License, Version 1.0. (See accompanying
7 // file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
9 // See http://www.boost.org/libs/format for library home page
11 // ----------------------------------------------------------------------------
13 #ifndef BOOST_FORMAT_EXCEPTIONS_HPP
14 #define BOOST_FORMAT_EXCEPTIONS_HPP
24 // **** exceptions -----------------------------------------------
26 class format_error : public std::exception
30 virtual const char *what() const throw() {
31 return "boost::format_error: "
32 "format generic failure";
36 class bad_format_string : public format_error
38 std::size_t pos_, next_;
40 bad_format_string(std::size_t pos, std::size_t size)
41 : pos_(pos), next_(size) {}
42 std::size_t get_pos() const { return pos_; }
43 std::size_t get_next() const { return next_; }
44 virtual const char *what() const throw() {
45 return "boost::bad_format_string: format-string is ill-formed";
49 class too_few_args : public format_error
51 std::size_t cur_, expected_;
53 too_few_args(std::size_t cur, std::size_t expected)
54 : cur_(cur), expected_(expected) {}
55 std::size_t get_cur() const { return cur_; }
56 std::size_t get_expected() const { return expected_; }
57 virtual const char *what() const throw() {
58 return "boost::too_few_args: "
59 "format-string refered to more arguments than were passed";
63 class too_many_args : public format_error
65 std::size_t cur_, expected_;
67 too_many_args(std::size_t cur, std::size_t expected)
68 : cur_(cur), expected_(expected) {}
69 std::size_t get_cur() const { return cur_; }
70 std::size_t get_expected() const { return expected_; }
71 virtual const char *what() const throw() {
72 return "boost::too_many_args: "
73 "format-string refered to less arguments than were passed";
78 class out_of_range : public format_error
80 int index_, beg_, end_; // range is [ beg, end [
82 out_of_range(int index, int beg, int end)
83 : index_(index), beg_(beg), end_(end) {}
84 int get_index() const { return index_; }
85 int get_beg() const { return beg_; }
86 int get_end() const { return end_; }
87 virtual const char *what() const throw() {
88 return "boost::out_of_range: "
89 "tried to refer to an argument (or item) number which"
90 " is out of range, according to the format string.";
100 #endif // BOOST_FORMAT_EXCEPTIONS_HPP