mulwidgets/common/inc/mulleave.h
branchRCL_3
changeset 20 0e9bb658ef58
parent 0 e83bab7cf002
equal deleted inserted replaced
19:4ea6f81c838a 20:0e9bb658ef58
       
     1 /*
       
     2 * Copyright (c) 2007-2008 Nokia Corporation and/or its subsidiary(-ies). 
       
     3 * All rights reserved.
       
     4 * This component and the accompanying materials are made available
       
     5 * under the terms of "Eclipse Public License v1.0"
       
     6 * which accompanies this distribution, and is available
       
     7 * at the URL "http://www.eclipse.org/legal/epl-v10.html".
       
     8 *
       
     9 * Initial Contributors:
       
    10 * Nokia Corporation - initial contribution.
       
    11 *
       
    12 * Contributors:
       
    13 *
       
    14 * Description:  Implementation for Leave to Throw macro
       
    15 *
       
    16 */
       
    17 
       
    18 
       
    19 #ifndef MULLEAVE_H
       
    20 #define MULLEAVE_H
       
    21 
       
    22 #include <stdexcept>
       
    23 	
       
    24 namespace Alf
       
    25 	{
       
    26 
       
    27 static const char* const KLeaveError = "Leave occured";
       
    28 	
       
    29 class MulLeave
       
    30     {
       
    31 
       
    32 public:
       
    33     
       
    34     static void ThrowOnError( int aError )
       
    35         {
       
    36         switch ( aError )
       
    37             {
       
    38             case KErrNone: 
       
    39             	{
       
    40                 // do nothing
       
    41                 break;
       
    42             	}
       
    43                 
       
    44             case KErrNoMemory:
       
    45             	{
       
    46                 throw std::bad_alloc(); 
       
    47             	}
       
    48                 
       
    49             // add other errors here if specific exception need to throw
       
    50             case KErrGeneral: // fall through
       
    51             default:
       
    52             	{
       
    53                 throw std::logic_error( KLeaveError ); 
       
    54             	}
       
    55             }
       
    56         }
       
    57     };
       
    58 	
       
    59 	} // namespace Alf
       
    60 
       
    61 #define THROW_IF_LEAVES(code) TRAPD( _leave_error, { code; } ); \
       
    62     						  Alf::MulLeave::ThrowOnError( _leave_error ); 
       
    63 
       
    64 #endif  // MULLEAVE_H
       
    65 
       
    66 // End of file
       
    67