tizen开发(3)

1. 3 different result reporting method types:
1) result SomeClass::DoSomething(..)
Result of the method execution is passed as a return value.
2) SomeClass* SomeClass::DoSomething
Returns a pointer of SomeClass if the method execution succeeds. It might return null if an error occurs.
Calling the GetLastResult() method after the execution of this method gives you the last result (exception).
3) Value-type (or void) SomeClass::DoSomething(..)
Returns by value (including void) and throws no errors in most cases. If the API reference of this method specifies exception types, calling the GetLastResult() method after the execution of this method gives you the last result.

2. 3 methods to handle the result value:
1) GetLastResult()
Returns the last error or the result set with the SetLastResult() method. This value is unique per thread and persists until the SetLastResult() method is called for that thread again. Consequently, you do not get the correct error value if you invoke the GetLastResult() method on a thread other than the caller thread of the method.
2) SetLastResult()
Changes the result value.
3) GetErrorMessage()
Returns a char* instance containing the result's message.

3. exception check
1) When the method returns a result:
result r = E_SUCCESS;

// Construct a list
r = list.Construct(...);
if (IsFailed(r)) // Identical to if (r != E_SUCCESS)
{
   // Error handling


2) When the method sets the error code by invoking the SetLastResult() method and returns a null pointer:
pObj = list.GetAt(...);
if (GetLastResult() != E_SUCCESS) // Or if (pObj == null)
{
   // Error handling


4. Exception Propagation
1) Using goto CATCH:
result r = E_SUCCESS;
// Construct a list
r = pList->Construct(...);
TryCatch(r == E_SUCCESS, delete pList, "[%s] Propagating.", GetErrorMessage(r));

CATCH:
   return r;
 2) Returning a result:
 r = list.Construct(...);
TryReturn(r == E_SUCCESS, r, "[%s] Propagating.", GetErrorMessage(r));
3) Returning a null:
r = list.Construct(...);
TryReturn(r == E_SUCCESS, null, "[%s] Propagating.", GetErrorMessage(r));
4) Converting an error condition into another error condition:
r = list.indexOf(...);
TryReturn(r == E_SUCCESS, E_INVALID_ARG, "'%s' converted to [E_INVALID_ARG].", GetErrorMessage(r));
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值