|
|
1.1 root 1: /*
1.1.1.6 root 2: Copyright (c) 2008 TrueCrypt Developers Association. All rights reserved.
1.1 root 3:
1.1.1.7 ! root 4: Governed by the TrueCrypt License 3.0 the full text of which is contained in
1.1.1.6 root 5: the file License.txt included in TrueCrypt binary and source code distribution
6: packages.
1.1 root 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); \
1.1.1.3 root 88: TC_EXCEPTION (PartitionDeviceRequired); \
1.1 root 89: TC_EXCEPTION (StringConversionFailed); \
90: TC_EXCEPTION (TestFailed); \
91: TC_EXCEPTION (TimeOut); \
1.1.1.3 root 92: TC_EXCEPTION (UnknownException); \
93: TC_EXCEPTION (UserAbort)
1.1 root 94:
95: TC_EXCEPTION_SET;
96:
97: #undef TC_EXCEPTION
98: }
99:
100: #ifdef assert
101: # undef assert
102: #endif
103:
104: #ifdef DEBUG
105: # define assert(condition) do { if (!(condition)) throw AssertionFailed (SRC_POS); } while (false)
106: #else
107: # define assert(condition) ((void) 0)
108: #endif
109:
110: #endif // TC_HEADER_Platform_Exception
This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.