core/src/error.h
changeset 0 7f656887cf89
child 78 b3ffff030d5c
equal deleted inserted replaced
-1:000000000000 0:7f656887cf89
       
     1 // error.h
       
     2 // 
       
     3 // Copyright (c) 2008 - 2010 Accenture. All rights reserved.
       
     4 // This component and the accompanying materials are made available
       
     5 // under the terms of the "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 // Accenture - Initial contribution
       
    11 //
       
    12 
       
    13 
       
    14 #ifndef __ERROR_H__
       
    15 #define __ERROR_H__
       
    16 
       
    17 #include <e32base.h>
       
    18 
       
    19 class RIoWriteHandle;
       
    20 namespace IoUtils
       
    21 	{
       
    22 	class CEnvironment;
       
    23 	}
       
    24 
       
    25 
       
    26 class TError
       
    27 	{
       
    28 public:
       
    29 	enum TReason
       
    30 		{
       
    31 		EUnknown,
       
    32 		EFailedToCreatePipeLine,
       
    33 		EFailedToConstructCommand,
       
    34 		EFailedToRunCommand,
       
    35 		EFailedToSetChildErrorVar,
       
    36 		ECommandError,
       
    37 		EFailedToSetScriptLineVar,
       
    38 		};
       
    39 public:
       
    40 	TError(RIoWriteHandle& aStderr, IoUtils::CEnvironment& aEnv);
       
    41 	void Set(const TError& aError);
       
    42 	void Set(TInt aError, TReason aReason);
       
    43 	void Set(TInt aError, TReason aReason, TRefByValue<const TDesC> aFmt, ...);
       
    44 	void Report() const;
       
    45 	TInt Error() const;
       
    46 	TReason Reason() const;
       
    47 	const TDesC* Context() const;
       
    48 	const TDesC& ScriptFileName() const;
       
    49 	TInt ScriptLineNumber() const;
       
    50 private:
       
    51 	void Format(TRefByValue<const TDesC> aFmt, ...);
       
    52 	void FormatList(TRefByValue<const TDesC> aFmt, VA_LIST& aList);
       
    53 	void LogIfRequired(TInt aError, TReason aReason, TRefByValue<const TDesC> aFmt, ...);
       
    54 	void LogListIfRequired(TInt aError, TReason aReason, TRefByValue<const TDesC> aFmt, VA_LIST& aList);
       
    55 	const TDesC* StringifyReason(TReason aReason) const;
       
    56 	TBool Verbose() const;
       
    57 	void NewLine() const;
       
    58 	void PrintError() const;
       
    59 	void FormatError(TRefByValue<const TDesC> aFmt, ...) const;
       
    60 private:
       
    61 	RIoWriteHandle* iStderr;
       
    62 	IoUtils::CEnvironment* iEnv;
       
    63 	TInt iError;
       
    64 	TReason iReason;
       
    65 	TBool iSet;
       
    66 	TBuf<256> iContext;
       
    67 	mutable TBuf<512> iScratch;
       
    68 	TFileName iScriptFileName;
       
    69 	TInt iScriptLineNumber;
       
    70 	};
       
    71 
       
    72 
       
    73 #endif // __ERROR_H__