"Fossies" - the Fresh Open Source Software Archive

Member "src/Platform/Exception.h" (10 Oct 2018, 3589 Bytes) of package /windows/misc/VeraCrypt_1.23-Hotfix-2_Source.zip:


As a special service "Fossies" has tried to format the requested source page into HTML format using (guessed) C and C++ source code syntax highlighting (style: standard) with prefixed line numbers and code folding option. Alternatively you can here view or download the uninterpreted source code file. For more information about "Exception.h" see the Fossies "Dox" file reference documentation.

    1 /*
    2  Derived from source code of TrueCrypt 7.1a, which is
    3  Copyright (c) 2008-2012 TrueCrypt Developers Association and which is governed
    4  by the TrueCrypt License 3.0.
    5 
    6  Modifications and additions to the original source code (contained in this file)
    7  and all other portions of this file are Copyright (c) 2013-2017 IDRIX
    8  and are governed by the Apache License 2.0 the full text of which is
    9  contained in the file License.txt included in VeraCrypt binary and source
   10  code distribution packages.
   11 */
   12 
   13 #ifndef TC_HEADER_Platform_Exception
   14 #define TC_HEADER_Platform_Exception
   15 
   16 #include <exception>
   17 #include "PlatformBase.h"
   18 #include "Serializable.h"
   19 
   20 namespace VeraCrypt
   21 {
   22 #define TC_SERIALIZABLE_EXCEPTION(TYPE) TC_SERIALIZABLE (TYPE); \
   23     virtual Exception *CloneNew () { return new TYPE (*this); } \
   24     virtual void Throw () const { throw *this; }
   25 
   26     struct Exception : public exception, public Serializable
   27     {
   28     public:
   29         Exception () { }
   30         Exception (const string &message) : Message (message) { }
   31         Exception (const string &message, const wstring &subject) : Message (message), Subject (subject) { }
   32         virtual ~Exception () throw () { }
   33 
   34         TC_SERIALIZABLE_EXCEPTION (Exception);
   35 
   36         virtual const char *what () const throw () { return Message.c_str(); }
   37         virtual const wstring &GetSubject() const { return Subject; }
   38 
   39     protected:
   40         string Message;
   41         wstring Subject;
   42     };
   43 
   44     struct ExecutedProcessFailed : public Exception
   45     {
   46         ExecutedProcessFailed () { }
   47         ExecutedProcessFailed (const string &message, const string &command, int exitCode, const string &errorOutput)
   48             : Exception (message), Command (command), ExitCode (exitCode), ErrorOutput (errorOutput) { }
   49         virtual ~ExecutedProcessFailed () throw () { }
   50 
   51         TC_SERIALIZABLE_EXCEPTION (ExecutedProcessFailed);
   52 
   53         string GetCommand () const { return Command; }
   54         int64 GetExitCode () const { return ExitCode; }
   55         string GetErrorOutput () const { return ErrorOutput; }
   56 
   57     protected:
   58         string Command;
   59         int64 ExitCode;
   60         string ErrorOutput;
   61     };
   62 
   63 #define TC_EXCEPTION_DECL(NAME,BASE) \
   64     struct NAME  : public BASE \
   65     { \
   66         NAME () { } \
   67         NAME (const string &message) : BASE (message) { } \
   68         NAME (const string &message, const wstring &subject) : BASE (message, subject) { } \
   69         virtual Exception *CloneNew () { return new NAME (*this); } \
   70         static Serializable *GetNewSerializable () { return new NAME (); } \
   71         virtual void Throw () const { throw *this; } \
   72     }
   73 
   74 #define TC_EXCEPTION_NODECL(dummy) //
   75 #define TC_EXCEPTION(NAME) TC_EXCEPTION_DECL(NAME,Exception)
   76 
   77 #ifdef TC_EXCEPTION_SET
   78 #undef TC_EXCEPTION_SET
   79 #endif
   80 #define TC_EXCEPTION_SET \
   81     TC_EXCEPTION_NODECL (Exception); \
   82     TC_EXCEPTION_NODECL (ExecutedProcessFailed); \
   83     TC_EXCEPTION (AlreadyInitialized); \
   84     TC_EXCEPTION (AssertionFailed); \
   85     TC_EXCEPTION (ExternalException); \
   86     TC_EXCEPTION (InsufficientData); \
   87     TC_EXCEPTION (NotApplicable); \
   88     TC_EXCEPTION (NotImplemented); \
   89     TC_EXCEPTION (NotInitialized); \
   90     TC_EXCEPTION (ParameterIncorrect); \
   91     TC_EXCEPTION (ParameterTooLarge); \
   92     TC_EXCEPTION (PartitionDeviceRequired); \
   93     TC_EXCEPTION (StringConversionFailed); \
   94     TC_EXCEPTION (TestFailed); \
   95     TC_EXCEPTION (TimeOut); \
   96     TC_EXCEPTION (UnknownException); \
   97     TC_EXCEPTION (UnsupportedAlgoInTrueCryptMode); \
   98     TC_EXCEPTION (UnsupportedTrueCryptFormat); \
   99     TC_EXCEPTION (UserAbort)
  100 
  101     TC_EXCEPTION_SET;
  102 
  103 #undef TC_EXCEPTION
  104 }
  105 
  106 #ifdef assert
  107 #   undef assert
  108 #endif
  109 
  110 #ifdef DEBUG
  111 #   define assert(condition) do { if (!(condition)) throw AssertionFailed (SRC_POS); } while (false)
  112 #else
  113 #   define assert(condition) ((void) 0)
  114 #endif
  115 
  116 #endif // TC_HEADER_Platform_Exception