ICU 64.2
64.2
|
Wrapper class for UErrorCode, with conversion operators for direct use in ICU C and C++ APIs. More...
#include <errorcode.h>
Public Member Functions | |
ErrorCode () | |
Default constructor. More... | |
virtual | ~ErrorCode () |
Destructor, does nothing. More... | |
operator UErrorCode & () | |
Conversion operator, returns a reference. More... | |
operator UErrorCode * () | |
Conversion operator, returns a pointer. More... | |
UBool | isSuccess () const |
Tests for U_SUCCESS(). More... | |
UBool | isFailure () const |
Tests for U_FAILURE(). More... | |
UErrorCode | get () const |
Returns the UErrorCode value. More... | |
void | set (UErrorCode value) |
Sets the UErrorCode value. More... | |
UErrorCode | reset () |
Returns the UErrorCode value and resets it to U_ZERO_ERROR. More... | |
void | assertSuccess () const |
Asserts isSuccess(). More... | |
const char * | errorName () const |
Return a string for the UErrorCode value. More... | |
Protected Member Functions | |
virtual void | handleFailure () const |
Called by assertSuccess() if isFailure() is true. More... | |
Protected Attributes | |
UErrorCode | errorCode |
Internal UErrorCode, accessible to subclasses. More... | |
Wrapper class for UErrorCode, with conversion operators for direct use in ICU C and C++ APIs.
Intended to be used as a base class, where a subclass overrides the handleFailure() function so that it throws an exception, does an assert(), logs an error, etc. This is not an abstract base class. This class can be used and instantiated by itself, although it will be more useful when subclassed.
Features:
Note: For automatic checking for success in the destructor, a subclass must implement such logic in its own destructor because the base class destructor cannot call a subclass function (like handleFailure()). The ErrorCode base class destructor does nothing.
Note also: While it is possible for a destructor to throw an exception, it is generally unsafe to do so. This means that in a subclass the destructor and the handleFailure() function may need to take different actions.
Sample code:
Definition at line 81 of file errorcode.h.
|
inline |
Default constructor.
Initializes its UErrorCode to U_ZERO_ERROR.
Definition at line 87 of file errorcode.h.
|
virtual |
void icu::ErrorCode::assertSuccess | ( | ) | const |
Asserts isSuccess().
In other words, this method checks for a failure code, and the base class handles it like this:
const char* icu::ErrorCode::errorName | ( | ) | const |
Return a string for the UErrorCode value.
The string will be the same as the name of the error code constant in the UErrorCode enum.
|
inline |
|
inlineprotectedvirtual |
Called by assertSuccess() if isFailure() is true.
A subclass should override this function to deal with a failure code: Throw an exception, log an error, terminate the program, or similar.
Definition at line 134 of file errorcode.h.
References U_NAMESPACE_END.
|
inline |
Tests for U_FAILURE().
Definition at line 97 of file errorcode.h.
References U_FAILURE.
|
inline |
Tests for U_SUCCESS().
Definition at line 95 of file errorcode.h.
References U_SUCCESS.
|
inline |
|
inline |
UErrorCode icu::ErrorCode::reset | ( | ) |
Returns the UErrorCode value and resets it to U_ZERO_ERROR.
|
inline |
|
protected |
Internal UErrorCode, accessible to subclasses.
Definition at line 127 of file errorcode.h.