Boost C++ Libraries: Ticket #12582: Error catching specific "regex_error" https://svn.boost.org/trac10/ticket/12582 <p> The following try catch doesn't work in 1.61, but did work in 1.55. Other boost exceptions are caught properly. I've provided two examples (one working, one failing) </p> <h2 class="section" id="Exceptionisnevercaught">Exception is never caught</h2> <pre class="wiki">try { boost::smatch m1; std::string long_String= "@VOOfPHslmjhdQGM4CHjMII4tf-5-FjBnxaC6D8C3jQs09cdw8gDlF0bI7jfmN6cGKeZdJVOCt5GoeOVA3ao35rN-NV3Oy3A9V2hMUO0hHHVdWeGSoRY8ua3lnsXZsaOmz9YTZhR-Xtq13xAnYP5sHHbfM6tuuqWetdgCGNeMlckGyEKBW0MTtRq7Lhns8t7QW_59x77LRz2n0LtSS46sdN970eQ04llaeXZQDUv4coz6VuOBmEUUfLcxxc3HACSqdLQ-EmD_olxqPjR_mO2_ltjv_m2edvtn-5psCXZVpdVLKtcjl8ezLJQx5l30tIiPWkLDP_jot-lUe7ypMjXY68fo_E33L3eIyVTzyCWLSQdC9616-xA9gpMlHLDYOZL9MsxeOsK5v86OYkTn88IDtWV_bXfdEsN9m_p1CYKjwyhlBWH1h3uSz0WAzcIqqMDkNbQrF8sFmX7fVSC5OhazMnJHRnfcKCHfyCoTqA5horkQn0Kded3qFdtnZEvrOKgrGeiLjNwwlPuRQI2pD9StWHiI5b2ACyJ2wV8Xl7f4FKhr3H6xXpWKTEXNt4VjWZgfcVq9UCiThSLEBfHOEe1voARPHrDBw26VSjHVWacUZAAJ6Cf4AXsx8kvBsiw4HKyG6qdlYp6v03BEtLv_vP2neOGrDQAV5s9ED_qGGJVDgAxb_auZwL5lNE5Sw0KdWDBd"; static const boost::regex b1("((?:[A-z0-9]+|[A-z\\-]+ ?)?(?: the )?(?:[Ss][Pp][Ii][Dd][Ee][Rr]|[Ss]crape|[A-Za-z0-9-]*(?:[^C][^Uu])[Bb]ot|[Cc][Rr][Aa][Ww][Ll])[A-z0-9]*)(?:(?:[ /]| v)(\\d+)(?:\\.(\\d+)(?:\\.(\\d+))?)?)?"); boost::regex_search(sample_kaspersky, m1, b1); } catch (...) { //should catch a regex_error: The complexity of matching the regular expression exceeded predefined bounds.... } </pre><p> The previous code block doesn't catch the exception but instead calls terminate: </p> <pre class="wiki">terminate called after throwing an instance of 'boost::exception_detail::clone_impl&lt;boost::exception_detail::error_info_injector&lt;std::runtime_error&gt; &gt;' what(): The complexity of matching the regular expression exceeded predefined bounds. Try refactoring the regular expression to make each choice made by the state machine unambiguous. This exception is thrown to prevent "eternal" matches that take an indefinite period time to locate. </pre><h2 class="section" id="Exceptioniscaughtproperly">Exception is caught properly</h2> <pre class="wiki"> try { // forcing an exception static const boost::regex b2("((?:[?)?)?"); boost::smatch m2; boost::regex_search(sample_kaspersky, m2, b2); } catch (...) { //this work perfectly } </pre> en-us Boost C++ Libraries /htdocs/site/boost.png https://svn.boost.org/trac10/ticket/12582 Trac 1.4.3 John Maddock Thu, 09 Feb 2017 18:50:17 GMT <link>https://svn.boost.org/trac10/ticket/12582#comment:1 </link> <guid isPermaLink="false">https://svn.boost.org/trac10/ticket/12582#comment:1</guid> <description> <p> With apologies for the delay, this works fine for me here, what compiler/platform are you using? </p> <p> This smells like an installation error (linking against the wrong regex lib version). </p> </description> <category>Ticket</category> </item> </channel> </rss>