OR_LEAVE macro Tutorial

Macro is a rule or pattern that specifies how a certain input sequence should be mapped to an output sequence according to a defined procedure. This tutorial describes the OR_LEAVE macro and provides details on how the OR_LEAVE macro should be used.

Required background

Before beginning you must know the following:

  • UserLeaveIfError() : Error handling code. This function is called when a client is passing a file for a server to handle.

Introduction

The OR_LEAVE macro is a convenience macro that allows the developer to deemphasize auxiliary error checking code in most cases. It is a postfix macro which implements User::LeaveIfError() on an integer return type. This means that there is less focus on the error handling code and makes the code easier to read.

The OR_LEAVE macro is defined as a postfix operator. An example code snippet is shown below:

       
        
       
       #define OR_LEAVE || Eleave
inline void operator||(Tint aStatus, Tleave /*aTag*/)
    {
    User::LeaveIfError(aStatus);
    }
      

It is a postfix macro which implements User::LeaveIfError() function on an integer return type. This means that there is less focus on the error handling code and makes the code easier to read.

Using OR_LEAVE macro

The OR_LEAVE is used to replace a call to User::LeaveIfError() function. An example code snippet is shown below:

       User::LeaveIfError(iTimer->CreateLocal());
      

The call to iTimer->CreateLocal() is included within the error handling code User::LeaveIfError() function and is difficult to read. The following fragment uses the OR_LEAVE macro.

       iTimer->CreateLocal() OR_LEAVE;