sl@0: // ---------------------------------------------------------------------------- sl@0: // boost/format/exceptions.hpp sl@0: // ---------------------------------------------------------------------------- sl@0: sl@0: // Copyright Samuel Krempp 2003. sl@0: // sl@0: // Distributed under the Boost Software License, Version 1.0. sl@0: // (See accompanying file LICENSE_1_0.txt or copy at sl@0: // http://www.boost.org/LICENSE_1_0.txt) sl@0: // sl@0: // sl@0: // See http://www.boost.org/libs/format/ for library home page sl@0: sl@0: // ---------------------------------------------------------------------------- sl@0: sl@0: #ifndef BOOST_FORMAT_EXCEPTIONS_HPP sl@0: #define BOOST_FORMAT_EXCEPTIONS_HPP sl@0: sl@0: sl@0: #include sl@0: sl@0: sl@0: namespace boost { sl@0: sl@0: namespace io { sl@0: sl@0: // **** exceptions ----------------------------------------------- sl@0: sl@0: class format_error : public std::exception sl@0: { sl@0: public: sl@0: format_error() {} sl@0: virtual const char *what() const throw() { sl@0: return "boost::format_error: " sl@0: "format generic failure"; sl@0: } sl@0: }; sl@0: sl@0: class bad_format_string : public format_error sl@0: { sl@0: std::size_t pos_, next_; sl@0: public: sl@0: bad_format_string(std::size_t pos, std::size_t size) sl@0: : pos_(pos), next_(size) {} sl@0: std::size_t get_pos() const { return pos_; } sl@0: std::size_t get_next() const { return next_; } sl@0: virtual const char *what() const throw() { sl@0: return "boost::bad_format_string: format-string is ill-formed"; sl@0: } sl@0: }; sl@0: sl@0: class too_few_args : public format_error sl@0: { sl@0: std::size_t cur_, expected_; sl@0: public: sl@0: too_few_args(std::size_t cur, std::size_t expected) sl@0: : cur_(cur), expected_(expected) {} sl@0: std::size_t get_cur() const { return cur_; } sl@0: std::size_t get_expected() const { return expected_; } sl@0: virtual const char *what() const throw() { sl@0: return "boost::too_few_args: " sl@0: "format-string referred to more arguments than were passed"; sl@0: } sl@0: }; sl@0: sl@0: class too_many_args : public format_error sl@0: { sl@0: std::size_t cur_, expected_; sl@0: public: sl@0: too_many_args(std::size_t cur, std::size_t expected) sl@0: : cur_(cur), expected_(expected) {} sl@0: std::size_t get_cur() const { return cur_; } sl@0: std::size_t get_expected() const { return expected_; } sl@0: virtual const char *what() const throw() { sl@0: return "boost::too_many_args: " sl@0: "format-string referred to less arguments than were passed"; sl@0: } sl@0: }; sl@0: sl@0: sl@0: class out_of_range : public format_error sl@0: { sl@0: int index_, beg_, end_; // range is [ beg, end [ sl@0: public: sl@0: out_of_range(int index, int beg, int end) sl@0: : index_(index), beg_(beg), end_(end) {} sl@0: int get_index() const { return index_; } sl@0: int get_beg() const { return beg_; } sl@0: int get_end() const { return end_; } sl@0: virtual const char *what() const throw() { sl@0: return "boost::out_of_range: " sl@0: "tried to refer to an argument (or item) number which" sl@0: " is out of range, according to the format string"; sl@0: } sl@0: }; sl@0: sl@0: sl@0: } // namespace io sl@0: sl@0: } // namespace boost sl@0: sl@0: sl@0: #endif // BOOST_FORMAT_EXCEPTIONS_HPP