1///////////////////////////////////////////////////////////////////////////////
2/// \file regex_error.hpp
3/// Contains the definition of the regex_error exception class.
4//
5// Copyright 2008 Eric Niebler. Distributed under the Boost
6// Software License, Version 1.0. (See accompanying file
7// LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
8
9#ifndef BOOST_XPRESSIVE_REGEX_ERROR_HPP_EAN_10_04_2005
10#define BOOST_XPRESSIVE_REGEX_ERROR_HPP_EAN_10_04_2005
11
12// MS compatible compilers support #pragma once
13#if defined(_MSC_VER)
14# pragma once
15#endif
16
17#include <string>
18#include <stdexcept>
19#include <boost/throw_exception.hpp>
20#include <boost/current_function.hpp>
21#include <boost/exception/exception.hpp>
22#include <boost/exception/info.hpp>
23#include <boost/xpressive/regex_constants.hpp>
24
25//{{AFX_DOC_COMMENT
26///////////////////////////////////////////////////////////////////////////////
27// This is a hack to get Doxygen to show the inheritance relation between
28// regex_error and std::runtime_error.
29#ifdef BOOST_XPRESSIVE_DOXYGEN_INVOKED
30/// INTERNAL ONLY
31namespace std
32{
33 /// INTERNAL ONLY
34 struct runtime_error {};
35}
36#endif
37//}}AFX_DOC_COMMENT
38
39namespace boost { namespace xpressive
40{
41
42////////////////////////////////////////////////////////////////////////////////
43// regex_error
44//
45/// \brief The class regex_error defines the type of objects thrown as
46/// exceptions to report errors during the conversion from a string representing
47/// a regular expression to a finite state machine.
48struct regex_error
49 : std::runtime_error
50 , boost::exception
51{
52 /// Constructs an object of class regex_error.
53 /// \param code The error_type this regex_error represents.
54 /// \param str The message string of this regex_error.
55 /// \post code() == code
56 explicit regex_error(regex_constants::error_type code, char const *str = "")
57 : std::runtime_error(str)
58 , boost::exception()
59 , code_(code)
60 {
61 }
62
63 /// Accessor for the error_type value
64 /// \return the error_type code passed to the constructor
65 /// \throw nothrow
66 regex_constants::error_type code() const
67 {
68 return this->code_;
69 }
70
71 /// Destructor for class regex_error
72 /// \throw nothrow
73 virtual ~regex_error() throw()
74 {}
75
76private:
77
78 regex_constants::error_type code_;
79};
80
81namespace detail
82{
83 inline bool ensure_(
84 bool cond
85 , regex_constants::error_type code
86 , char const *msg
87 , char const *fun
88 , char const *file
89 , unsigned long line
90 )
91 {
92 if(!cond)
93 {
94 #ifndef BOOST_EXCEPTION_DISABLE
95 boost::throw_exception(
96 e: boost::xpressive::regex_error(code, msg)
97 << boost::throw_function(fun)
98 << boost::throw_file(file)
99 << boost::throw_line((int)line)
100 );
101 #else
102 boost::throw_exception(boost::xpressive::regex_error(code, msg));
103 #endif
104 }
105 return true;
106 }
107}
108
109#define BOOST_XPR_ENSURE_(pred, code, msg) \
110 boost::xpressive::detail::ensure_(!!(pred), code, msg, BOOST_CURRENT_FUNCTION, __FILE__, __LINE__) \
111 /**/
112
113}} // namespace boost::xpressive
114
115#endif
116

source code of boost/boost/xpressive/regex_error.hpp