From: Shane Carr Date: Fri, 2 Aug 2019 23:59:51 +0000 (-0700) Subject: ICU-20685 Improving docs for UErrorCode. X-Git-Tag: release-65-rc~74 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=2390ce569e465f46833dc37b55949f792d28906a;p=icu ICU-20685 Improving docs for UErrorCode. --- diff --git a/icu4c/source/common/unicode/utypes.h b/icu4c/source/common/unicode/utypes.h index f224ae496c0..8d8f54764e0 100644 --- a/icu4c/source/common/unicode/utypes.h +++ b/icu4c/source/common/unicode/utypes.h @@ -385,17 +385,31 @@ typedef double UDate; /*===========================================================================*/ /** - * Error code to replace exception handling, so that the code is compatible with all C++ compilers, - * and to use the same mechanism for C and C++. + * Standard ICU4C error code type, a substitute for exceptions. + * + * Initialize the UErrorCode with U_ZERO_ERROR, and check for success or + * failure using U_SUCCESS() or U_FAILURE(): + * + * UErrorCode errorCode = U_ZERO_ERROR; + * // call ICU API that needs an error code parameter. + * if (U_FAILURE(errorCode)) { + * // An error occurred. Handle it here. + * } + * + * C++ code should use icu::ErrorCode, available in unicode/errorcode.h, or a + * suitable subclass. + * + * For more information, see: + * http://icu-project.org/userguide/conventions + * + * Note: By convention, ICU functions that take a reference (C++) or a pointer + * (C) to a UErrorCode first test: + * + * if (U_FAILURE(errorCode)) { return immediately; } * - * \par - * ICU functions that take a reference (C++) or a pointer (C) to a UErrorCode - * first test if(U_FAILURE(errorCode)) { return immediately; } * so that in a chain of such functions the first one that sets an error code * causes the following ones to not perform any operations. * - * \par - * Error codes should be tested using U_FAILURE() and U_SUCCESS(). * @stable ICU 2.0 */ typedef enum UErrorCode {