source: NonGTP/Boost/boost/format/exceptions.hpp @ 857

Revision 857, 3.5 KB checked in by igarcia, 18 years ago (diff)
Line 
1// ----------------------------------------------------------------------------
2// boost/format/exceptions.hpp
3// ----------------------------------------------------------------------------
4
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)
8
9//  See http://www.boost.org/libs/format for library home page
10
11// ----------------------------------------------------------------------------
12
13#ifndef BOOST_FORMAT_EXCEPTIONS_HPP
14#define BOOST_FORMAT_EXCEPTIONS_HPP
15
16
17#include <stdexcept>
18
19
20namespace boost {
21
22    namespace io {
23
24// **** exceptions -----------------------------------------------
25
26        class format_error : public std::exception
27        {
28        public:
29            format_error()  {}
30            virtual const char *what() const throw() {
31                return "boost::format_error: "
32                    "format generic failure";
33            }
34        };
35
36        class bad_format_string : public format_error
37        {
38            std::size_t pos_, next_;
39        public:
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";
46            }
47        };
48
49        class too_few_args : public format_error
50        {
51            std::size_t cur_, expected_;
52        public:
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";
60            }
61        };
62
63        class too_many_args : public format_error
64        {
65            std::size_t cur_, expected_;
66        public:
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";
74            }
75        };
76
77
78        class  out_of_range : public format_error
79        {
80            int index_, beg_, end_;    // range is [ beg, end [
81        public:
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.";
91            }
92        };
93
94
95    } // namespace io
96
97} // namespace boost
98
99
100#endif // BOOST_FORMAT_EXCEPTIONS_HPP
Note: See TracBrowser for help on using the repository browser.