regex_error.h

Go to the documentation of this file.
00001 // class template regex -*- C++ -*-
00002 
00003 // Copyright (C) 2010 Free Software Foundation, Inc.
00004 //
00005 // This file is part of the GNU ISO C++ Library.  This library is free
00006 // software; you can redistribute it and/or modify it under the
00007 // terms of the GNU General Public License as published by the
00008 // Free Software Foundation; either version 3, or (at your option)
00009 // any later version.
00010 
00011 // This library is distributed in the hope that it will be useful,
00012 // but WITHOUT ANY WARRANTY; without even the implied warranty of
00013 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00014 // GNU General Public License for more details.
00015 
00016 // Under Section 7 of GPL version 3, you are granted additional
00017 // permissions described in the GCC Runtime Library Exception, version
00018 // 3.1, as published by the Free Software Foundation.
00019 
00020 // You should have received a copy of the GNU General Public License and
00021 // a copy of the GCC Runtime Library Exception along with this program;
00022 // see the files COPYING3 and COPYING.RUNTIME respectively.  If not, see
00023 // <http://www.gnu.org/licenses/>.
00024 
00025 /**
00026  * @file bits/regex_error.h
00027  * @brief Error and exception objects for the std regex library.
00028  *
00029  *  This is an internal header file, included by other library headers.
00030  *  You should not attempt to use it directly.
00031  */
00032 
00033 namespace std
00034 {
00035 
00036 namespace regex_constants
00037 {
00038   /**
00039    * @name 5.3 Error Types
00040    */
00041   //@{
00042  
00043   enum error_type
00044     {
00045       _S_error_collate,
00046       _S_error_ctype,
00047       _S_error_escape,
00048       _S_error_backref,
00049       _S_error_brack,
00050       _S_error_paren,
00051       _S_error_brace,
00052       _S_error_badbrace,
00053       _S_error_range,
00054       _S_error_space,
00055       _S_error_badrepeat,
00056       _S_error_complexity,
00057       _S_error_stack,
00058       _S_error_last
00059     };
00060 
00061   /** The expression contained an invalid collating element name. */
00062   static const error_type error_collate(_S_error_collate);
00063 
00064   /** The expression contained an invalid character class name. */
00065   static const error_type error_ctype(_S_error_ctype);
00066 
00067   /**
00068    * The expression contained an invalid escaped character, or a trailing
00069    * escape.
00070    */
00071   static const error_type error_escape(_S_error_escape);
00072 
00073   /** The expression contained an invalid back reference. */
00074   static const error_type error_backref(_S_error_backref);
00075 
00076   /** The expression contained mismatched [ and ]. */
00077   static const error_type error_brack(_S_error_brack);
00078 
00079   /** The expression contained mismatched ( and ). */
00080   static const error_type error_paren(_S_error_paren);
00081 
00082   /** The expression contained mismatched { and } */
00083   static const error_type error_brace(_S_error_brace);
00084 
00085   /** The expression contained an invalid range in a {} expression. */
00086   static const error_type error_badbrace(_S_error_badbrace);
00087 
00088   /**
00089    * The expression contained an invalid character range,
00090    * such as [b-a] in most encodings.
00091    */
00092   static const error_type error_range(_S_error_range);
00093 
00094   /**
00095    * There was insufficient memory to convert the expression into a
00096    * finite state machine.
00097    */
00098   static const error_type error_space(_S_error_space);
00099 
00100   /**
00101    * One of <em>*?+{<em> was not preceded by a valid regular expression.
00102    */
00103   static const error_type error_badrepeat(_S_error_badrepeat);
00104 
00105   /**
00106    * The complexity of an attempted match against a regular expression
00107    * exceeded a pre-set level.
00108    */
00109   static const error_type error_complexity(_S_error_complexity);
00110 
00111   /**
00112    * There was insufficient memory to determine whether the
00113    * regular expression could match the specified character sequence.
00114    */
00115   static const error_type error_stack(_S_error_stack);
00116 
00117   //@}
00118 }
00119 
00120   // [7.8] Class regex_error
00121   /**
00122    * @brief A regular expression exception class.
00123    * @ingroup exceptions
00124    *
00125    * The regular expression library throws objects of this class on error.
00126    */
00127   class regex_error
00128   : public std::runtime_error
00129   {
00130   public:
00131     /**
00132      * @brief Constructs a regex_error object.
00133      *
00134      * @param ecode the regex error code.
00135      */
00136     explicit
00137     regex_error(regex_constants::error_type __ecode)
00138     : std::runtime_error("regex_error"), _M_code(__ecode)
00139     { }
00140 
00141     /**
00142      * @brief Gets the regex error code.
00143      *
00144      * @returns the regex error code.
00145      */
00146     regex_constants::error_type
00147     code() const
00148     { return _M_code; }
00149 
00150   protected:
00151     regex_constants::error_type _M_code;
00152   };
00153 
00154 
00155   inline void
00156   __throw_regex_error(regex_constants::error_type __ecode)
00157   { throw regex_error(__ecode); }
00158 
00159 } // namespace std
00160