1// ----------------------------------------------------------------------------
2// boost/format/exceptions.hpp
3// ----------------------------------------------------------------------------
4
5// Copyright Samuel Krempp 2003.
6//
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)
10//
11//
12// See http://www.boost.org/libs/format/ for library home page
13
14// ----------------------------------------------------------------------------
15
16#ifndef BOOST_FORMAT_EXCEPTIONS_HPP
17#define BOOST_FORMAT_EXCEPTIONS_HPP
18
19
20#include <stdexcept>
21
22
23namespace boost {
24
25 namespace io {
26
27// **** exceptions -----------------------------------------------
28
29 class format_error : public std::exception
30 {
31 public:
32 format_error() {}
33 virtual const char *what() const throw() {
34 return "boost::format_error: "
35 "format generic failure";
36 }
37 };
38
39 class bad_format_string : public format_error
40 {
41 std::size_t pos_, next_;
42 public:
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";
49 }
50 };
51
52 class too_few_args : public format_error
53 {
54 std::size_t cur_, expected_;
55 public:
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";
63 }
64 };
65
66 class too_many_args : public format_error
67 {
68 std::size_t cur_, expected_;
69 public:
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 fewer arguments than were passed";
77 }
78 };
79
80
81 class out_of_range : public format_error
82 {
83 int index_, beg_, end_; // range is [ beg, end [
84 public:
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";
94 }
95 };
96
97
98 } // namespace io
99
100} // namespace boost
101
102
103#endif // BOOST_FORMAT_EXCEPTIONS_HPP
104