Module: Essential Tools Module Group: String Processing Classes
RWRegexErrRWInternalErr
#include <rw/rwerr.h> RWRegexErr msg("exception message");
Class RWRegexErr is an exception class used to report errors from within RWTRegex.
RWRegexErr is derived from RWInternalErr, and is therefore part of the RWxmsg class hierarchy. Classes in this hierarchy are used to report errors from within the Essential Tools Module.
RWRegexErr customizes RWInternalErr to provide not only an error message (inherited from RWxmsg), but also an error code and an error offset.
The error code is an RWTRegexStatus enumeration constant represented as a size_t, and is useful in generating error messages in the wide characters required for many non-Latin languages.
The error offset is the character offset into a pattern string at which a pattern compilation error occurred.
When RWTRegex<T> generates an error, it creates an RWRegexErr object to represent the error. A copy of this object is saved in the RWTRegex object, and is available through RWTRegex::getStatus()
Then, RWTHROW is used to report the error. If exceptions are enabled, then the RWRegexErr object is thrown as an exception. If not, a user-defined call-back function is invoked.
None
#include <rw/cstring.h> #include <rw/locale.h> #include <rw/rwerr.h> #include <rw/cstring.h> #include <rw/tools/regex.h> #include <iostream> int main() { const RWCString unmatchedParen("ab)$"); try { // Unmatched closing parenthesis generates exception RWTRegex<char> r(unmatchedParen); // Use the regular expression to avoid warnings r.index(unmatchedParen); } catch (const RWRegexErr& err) { std::cout << "Caught exception: " << std::endl << "Description : " << err.why() << std::endl << "Code : " << err.getCode() << std::endl << "Offset : " << err.getOffset() << std::endl << unmatchedParen << std::endl << RWCString('-', err.getOffset()) << '^' << std::endl; } return 0; }
Program output:
Caught exception: Description : Unmatched closing parenthesis Code : 8 Offset : 2 ab)$ --^
RWRegexErr(const char* msg, size_t eCode, size_t eOffset);
Constructor. Initializes the error object to contain the specified error message, msg. The error code, eCode, is stored as well as the offset into the pattern of the error.
RWRegexErr(const RWMessage& msg);
Creates an RWRegexErr from an RWMessage.
virtual ~RWRegexErr();
Destructor
const char* why();
Inherited from RWxmsg. Returns an error message describing the error that occurred.
size_t getCode() const
Returns the error code for the error.
size_t getOffset() const;
Returns the offset into the pattern at which the error occurred.
© Copyright Rogue Wave Software, Inc. All Rights Reserved.
Rogue Wave and SourcePro are registered trademarks of Rogue Wave Software, Inc. in the United States and other countries. All other trademarks are the property of their respective owners.
Contact Rogue Wave about documentation or support issues.