1 /*
2  *
3  * Copyright (c) 1998-2002
4  * John Maddock
5  *
6  * Use, modification and distribution are subject to the
7  * Boost Software License, Version 1.0. (See accompanying file
8  * LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
9  *
10  */
11 
12  /*
13   *   LOCATION:    see http://www.boost.org for most recent version.
14   *   FILE         pattern_except.hpp
15   *   VERSION      see <boost/version.hpp>
16   *   DESCRIPTION: Declares pattern-matching exception classes.
17   */
18 
19 #ifndef BOOST_RE_V5_PAT_EXCEPT_HPP
20 #define BOOST_RE_V5_PAT_EXCEPT_HPP
21 
22 #ifndef BOOST_REGEX_CONFIG_HPP
23 #include <boost/regex/config.hpp>
24 #endif
25 
26 #include <cstddef>
27 #include <stdexcept>
28 #include <boost/regex/v5/error_type.hpp>
29 #include <boost/regex/v5/regex_traits_defaults.hpp>
30 
31 namespace boost{
32 
33 #ifdef BOOST_REGEX_MSVC
34 #pragma warning(push)
35 #pragma warning(disable : 4275)
36 #if BOOST_REGEX_MSVC >= 1800
37 #pragma warning(disable : 26812 4459)
38 #endif
39 #endif
40 class regex_error : public std::runtime_error
41 {
42 public:
regex_error(const std::string & s,regex_constants::error_type err=regex_constants::error_unknown,std::ptrdiff_t pos=0)43    explicit regex_error(const std::string& s, regex_constants::error_type err = regex_constants::error_unknown, std::ptrdiff_t pos = 0)
44       : std::runtime_error(s)
45       , m_error_code(err)
46       , m_position(pos)
47    {
48    }
regex_error(regex_constants::error_type err)49    explicit regex_error(regex_constants::error_type err)
50       : std::runtime_error(::boost::BOOST_REGEX_DETAIL_NS::get_default_error_string(err))
51       , m_error_code(err)
52       , m_position(0)
53    {
54    }
~regex_error()55    ~regex_error() noexcept override {}
code() const56    regex_constants::error_type code()const
57    { return m_error_code; }
position() const58    std::ptrdiff_t position()const
59    { return m_position; }
raise() const60    void raise()const
61    {
62 #ifndef BOOST_NO_EXCEPTIONS
63 #ifndef BOOST_REGEX_STANDALONE
64       ::boost::throw_exception(*this);
65 #else
66       throw* this;
67 #endif
68 #endif
69    }
70 private:
71    regex_constants::error_type m_error_code;
72    std::ptrdiff_t m_position;
73 };
74 
75 typedef regex_error bad_pattern;
76 typedef regex_error bad_expression;
77 
78 namespace BOOST_REGEX_DETAIL_NS{
79 
80 template <class E>
raise_runtime_error(const E & ex)81 inline void raise_runtime_error(const E& ex)
82 {
83 #ifndef BOOST_REGEX_STANDALONE
84    ::boost::throw_exception(ex);
85 #else
86    throw ex;
87 #endif
88 }
89 
90 template <class traits>
raise_error(const traits & t,regex_constants::error_type code)91 void raise_error(const traits& t, regex_constants::error_type code)
92 {
93    (void)t;  // warning suppression
94    regex_error e(t.error_string(code), code, 0);
95    ::boost::BOOST_REGEX_DETAIL_NS::raise_runtime_error(e);
96 }
97 
98 }
99 
100 #ifdef BOOST_REGEX_MSVC
101 #pragma warning(pop)
102 #endif
103 
104 } // namespace boost
105 
106 #endif
107