secureswitools/swisistools/source/sisxlibrary/exception.h
changeset 0 ba25891c3a9e
equal deleted inserted replaced
-1:000000000000 0:ba25891c3a9e
       
     1 /*
       
     2 * Copyright (c) 2004-2009 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 the License "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: 
       
    15 *
       
    16 */
       
    17 
       
    18 
       
    19 /**
       
    20  @file 
       
    21  @publishedPartner
       
    22  @released
       
    23 */
       
    24 
       
    25 #ifndef __EXCEPTION_H__
       
    26 #define __EXCEPTION_H__
       
    27 
       
    28 #include <exception>
       
    29 
       
    30 #include "utility.h"
       
    31 
       
    32 
       
    33 class CSISException : public std::exception 
       
    34 	{
       
    35 public:
       
    36 	/**
       
    37 	 * Enumeration which represents errors while handling a sis file.
       
    38 	 */
       
    39 	typedef enum 
       
    40 		{
       
    41 		ENone,
       
    42 		EFileFormat,
       
    43 		EVerification,
       
    44 		EMemory,
       
    45 		EFileProblem,
       
    46 		ESyntax,
       
    47 		ECompress,
       
    48 		ECrypto,
       
    49 		ELanguage,
       
    50 		EUID,
       
    51 		ENotSigned,
       
    52 		EIllegal,
       
    53 		EInvalidDestination,
       
    54 		EInvalidInstallOption,
       
    55 		EDirIsFile,
       
    56 		EPermissionDenied,
       
    57 		ELegacyFormat,
       
    58 		ENotSupported
       
    59 		} TCategory;
       
    60 
       
    61 public:
       
    62 	/**
       
    63 	 * Constructor
       
    64 	 * @param aCategory type of exception
       
    65 	 * @param aContext context for the exception
       
    66 	 */
       
    67 	explicit CSISException (const TCategory aCategory, const std::string& aContext);
       
    68 	/**
       
    69 	 * Constructor
       
    70 	 * @param aCategory type of exception
       
    71 	 * @param aContext context for the exception
       
    72 	 */
       
    73 	explicit CSISException (const TCategory aCategory, const std::wstring& aContext);
       
    74 	/**
       
    75 	 * Cleanup owned resources
       
    76 	 */
       
    77 	virtual ~CSISException() throw ();
       
    78 	/**
       
    79 	 * Gets the exception detail or message.
       
    80 	 */
       
    81 	virtual const char *what () const throw() ;
       
    82 	/**
       
    83 	 * Gets the exception detail or message.
       
    84 	 */
       
    85 	virtual const wchar_t *widewhat () const throw();
       
    86 	/**
       
    87 	 * Gets the exception category
       
    88 	 */
       
    89 	TCategory ErrorCategory() const;
       
    90 
       
    91 	/**
       
    92 	 * Throws an exception if the condition is true.
       
    93 	 * @param aCondidtion Throws an exception if the condition is true.
       
    94 	 * @param aCategory type of exception
       
    95 	 * @param aContext context for the exception
       
    96 	 */
       
    97 	static void ThrowIf (const bool aCondition, const TCategory aCategory, const std::string& aContext);
       
    98 	/**
       
    99 	 * Throws an exception if the condition is true.
       
   100 	 * @param aCondidtion Throws an exception if the condition is true.
       
   101 	 * @param aCategory type of exception
       
   102 	 * @param aContext context for the exception
       
   103 	 */
       
   104 	static void ThrowIf (const bool aCondition, const TCategory aCategory, const std::wstring& aContext);
       
   105 
       
   106 
       
   107 private:
       
   108 	std::wstring iDescription;
       
   109 	TCategory iCategory;
       
   110 	};
       
   111 
       
   112 
       
   113 inline CSISException::CSISException (const TCategory aCategory, const std::string& aContext) :
       
   114 		std::exception (),
       
   115 		iDescription (string2wstring (aContext)),
       
   116 		iCategory (aCategory)
       
   117 	{
       
   118 	}
       
   119 	
       
   120 
       
   121 inline CSISException::CSISException (const TCategory aCategory, const std::wstring& aContext) :
       
   122 		std::exception (),
       
   123 		iDescription (aContext),
       
   124 		iCategory (aCategory)
       
   125 	{
       
   126 	}
       
   127 	
       
   128 
       
   129 inline CSISException::~CSISException () throw()
       
   130 	{
       
   131 	}
       
   132 
       
   133 
       
   134 inline void CSISException::ThrowIf (const bool aCondition, const TCategory aCategory, const std::string& aContext)
       
   135 	{
       
   136 	if (aCondition)
       
   137 		{
       
   138 		throw CSISException (aCategory, string2wstring (aContext));
       
   139 		}
       
   140 	}
       
   141 
       
   142 inline void CSISException::ThrowIf (const bool aCondition, const TCategory aCategory, const std::wstring& aContext)
       
   143 	{
       
   144 	if (aCondition)
       
   145 		{
       
   146 		throw CSISException (aCategory, aContext);
       
   147 		}
       
   148 	}
       
   149 
       
   150 inline CSISException::TCategory CSISException::ErrorCategory() const
       
   151 	{
       
   152 	return iCategory;
       
   153 	}
       
   154 
       
   155 
       
   156 #endif // __EXCEPTION_H__
       
   157