Skip to content

Latest commit

 

History

History
167 lines (137 loc) · 3.6 KB

File metadata and controls

167 lines (137 loc) · 3.6 KB
title regex_error Class | Microsoft Docs
ms.custom
ms.date 11/04/2016
ms.reviewer
ms.suite
ms.technology
cpp-standard-libraries
ms.tgt_pltfrm
ms.topic article
f1_keywords
regex_error
regex/std::regex_error
regex/std::regex_error::code
dev_langs
C++
helpviewer_keywords
regex_error class
ms.assetid 3333a1a3-ca6f-4612-84b2-1b4c7e3db5a4
caps.latest.revision 19
author corob-msft
ms.author corob
manager ghogen
translation.priority.mt
cs-cz
de-de
es-es
fr-fr
it-it
ja-jp
ko-kr
pl-pl
pt-br
ru-ru
tr-tr
zh-cn
zh-tw

regex_error Class

Reports a bad basic_regex object.

Syntax

class regex_error  
 : public std::runtime_error {  
public:  
    explicit regex_error(regex_constants::error_code error);

    regex_constants::error_code code() const;

 
 };  

Remarks

The class describes an exception object thrown to report an error in the construction or use of a basic_regex object.

Requirements

Header: <regex>

Namespace: std

regex_error::code

Returns the error code.

regex_constants::error_code code() const;

Remarks

The member function returns the value that was passed to the object's constructor.

Example

// std__regex__regex_error_code.cpp   
// compile with: /EHsc   
#include <regex>   
#include <iostream>   
  
int main()   
    {   
    std::regex_error paren(std::regex_constants::error_paren);   
  
    try   
        {   
        std::regex rx("(a");   
        }   
    catch (const std::regex_error& rerr)   
        {   
        std::cout << "regex error: "   
            << (rerr.code() == paren.code()   
                 "unbalanced parentheses" : "")   
            << std::endl;   
        }   
    catch (...)   
        {   
        std::cout << "unknown exception" << std::endl;   
        }   
  
    return (0);   
    }  
  
regex error: unbalanced parentheses  

regex_error::regex_error

Constructs the object.

regex_error(regex_constants::error_code error);

Parameters

error
The error code.

Remarks

The constructor constructs an object that holds the value error.

Example

// std__regex__regex_error_construct.cpp   
// compile with: /EHsc   
#include <regex>   
#include <iostream>   
  
int main()   
    {   
    std::regex_error paren(std::regex_constants::error_paren);   
  
    try   
        {   
        std::regex rx("(a");   
        }   
    catch (const std::regex_error& rerr)   
        {   
        std::cout << "regex error: "   
            << (rerr.code() == paren.code()   
                 "unbalanced parentheses" : "")   
            << std::endl;   
        }   
    catch (...)   
        {   
        std::cout << "unknown exception" << std::endl;   
        }   
  
    return (0);   
    }  
  
regex error: unbalanced parentheses  

See Also

<regex>
regex_constants Class
<regex> functions
regex_iterator Class
<regex> operators
regex_token_iterator Class
regex_traits Class
<regex> typedefs