ErrorCode Class Reference

Wrapper class for UErrorCode, with conversion operators for direct use in ICU C and C++ APIs. More...

#include <errorcode.h>

Inheritance diagram for ErrorCode:
UMemory

Public Member Functions

 ErrorCode ()
 Default constructor.
virtual ~ErrorCode ()
 Destructor, does nothing.
 operator UErrorCode & ()
 Conversion operator, returns a reference.
 operator UErrorCode * ()
 Conversion operator, returns a pointer.
UBool isSuccess () const
 Tests for U_SUCCESS().
UBool isFailure () const
 Tests for U_FAILURE().
UErrorCode get () const
 Returns the UErrorCode value.
void set (UErrorCode value)
 Sets the UErrorCode value.
UErrorCode reset ()
 Returns the UErrorCode value and resets it to U_ZERO_ERROR.
void check () const
 Checks for a failure code:.

Protected Member Functions

virtual void handleFailure () const
 Called by check() if isFailure() is true.

Protected Attributes

UErrorCode errorCode
 Internal UErrorCode, accessible to subclasses.

Detailed Description

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:

   class IcuErrorCode: public icu::ErrorCode {
   public:
     virtual ~IcuErrorCode() {
       // Safe because our handleFailure() does not throw exceptions.
       if(isFailure()) { handleFailure(); }
     }
   protected:
     virtual handleFailure() {
       log_failure(u_errorName(errorCode));
       exit(errorCode);
     }
   };
   IcuErrorCode error_code;
   UConverter *cnv = ucnv_open("Shift-JIS", error_code);
   length = ucnv_fromUChars(dest, capacity, src, length, error_code);
   ucnv_close(cnv);
   // IcuErrorCode destructor checks for success.
Draft:
This API may be changed in the future versions and was introduced in ICU 4.2

Definition at line 79 of file errorcode.h.


Constructor & Destructor Documentation

ErrorCode::ErrorCode (  )  [inline]

Default constructor.

Initializes its UErrorCode to U_ZERO_ERROR.

Draft:
This API may be changed in the future versions and was introduced in ICU 4.2

Definition at line 85 of file errorcode.h.

virtual ErrorCode::~ErrorCode (  )  [inline, virtual]

Destructor, does nothing.

See class documentation for details.

Draft:
This API may be changed in the future versions and was introduced in ICU 4.2

Definition at line 87 of file errorcode.h.


Member Function Documentation

void ErrorCode::check (  )  const

Checks for a failure code:.

   if(isFailure()) { handleFailure(); }
Draft:
This API may be changed in the future versions and was introduced in ICU 4.2
UErrorCode ErrorCode::get (  )  const [inline]

Returns the UErrorCode value.

Draft:
This API may be changed in the future versions and was introduced in ICU 4.2

Definition at line 97 of file errorcode.h.

virtual void ErrorCode::handleFailure (  )  const [inline, protected, virtual]

Called by check() 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.

Draft:
This API may be changed in the future versions and was introduced in ICU 4.2

Definition at line 123 of file errorcode.h.

UBool ErrorCode::isFailure (  )  const [inline]

Tests for U_FAILURE().

Draft:
This API may be changed in the future versions and was introduced in ICU 4.2

Definition at line 95 of file errorcode.h.

References U_FAILURE.

UBool ErrorCode::isSuccess (  )  const [inline]

Tests for U_SUCCESS().

Draft:
This API may be changed in the future versions and was introduced in ICU 4.2

Definition at line 93 of file errorcode.h.

References U_SUCCESS.

ErrorCode::operator UErrorCode & (  )  [inline]

Conversion operator, returns a reference.

Draft:
This API may be changed in the future versions and was introduced in ICU 4.2

Definition at line 89 of file errorcode.h.

ErrorCode::operator UErrorCode * (  )  [inline]

Conversion operator, returns a pointer.

Draft:
This API may be changed in the future versions and was introduced in ICU 4.2

Definition at line 91 of file errorcode.h.

UErrorCode ErrorCode::reset (  ) 

Returns the UErrorCode value and resets it to U_ZERO_ERROR.

Draft:
This API may be changed in the future versions and was introduced in ICU 4.2
void ErrorCode::set ( UErrorCode  value  )  [inline]

Sets the UErrorCode value.

Draft:
This API may be changed in the future versions and was introduced in ICU 4.2

Definition at line 99 of file errorcode.h.


Field Documentation

Internal UErrorCode, accessible to subclasses.

Draft:
This API may be changed in the future versions and was introduced in ICU 4.2

Definition at line 116 of file errorcode.h.


The documentation for this class was generated from the following file:
 All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Friends Defines

Generated on 9 Oct 2010 for ICU 4.2.1 by  doxygen 1.6.1