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