|
|
1.1 ! root 1: /* ! 2: Copyright (c) 2008 TrueCrypt Foundation. All rights reserved. ! 3: ! 4: Governed by the TrueCrypt License 2.6 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_Common_Exception ! 10: #define TC_HEADER_Common_Exception ! 11: ! 12: #include "Platform/PlatformBase.h" ! 13: #include "Dlgcode.h" ! 14: ! 15: namespace TrueCrypt ! 16: { ! 17: struct Exception ! 18: { ! 19: virtual void Show (HWND parent) const = 0; ! 20: }; ! 21: ! 22: struct SystemException : public Exception ! 23: { ! 24: SystemException () : ErrorCode (GetLastError()) { } ! 25: ! 26: void Show (HWND parent) const ! 27: { ! 28: SetLastError (ErrorCode); ! 29: handleWin32Error (parent); ! 30: } ! 31: ! 32: DWORD ErrorCode; ! 33: }; ! 34: ! 35: struct ErrorException : public Exception ! 36: { ! 37: ErrorException (char *langId) : ErrLangId (langId) { } ! 38: ErrorException (const wstring &errMsg) : ErrMsg (errMsg) { } ! 39: ! 40: void Show (HWND parent) const ! 41: { ! 42: if (ErrMsg.empty()) ! 43: ::Error (ErrLangId); ! 44: else ! 45: ::ErrorDirect (ErrMsg.c_str()); ! 46: } ! 47: ! 48: char *ErrLangId; ! 49: wstring ErrMsg; ! 50: }; ! 51: ! 52: struct ParameterIncorrect : public Exception ! 53: { ! 54: ParameterIncorrect (const char *srcPos) : SrcPos (srcPos) { } ! 55: ! 56: void Show (HWND parent) const ! 57: { ! 58: string msgBody = "Parameter incorrect.\n\n\n(If you report a bug in connection with this, please include the following technical information in the bug report:\n" + string (SrcPos) + ")"; ! 59: MessageBox (parent, msgBody.c_str(), "TrueCrypt", MB_ICONERROR | MB_SETFOREGROUND); ! 60: } ! 61: ! 62: const char *SrcPos; ! 63: }; ! 64: ! 65: struct TimeOut : public Exception ! 66: { ! 67: TimeOut (const char *srcPos) { } ! 68: void Show (HWND parent) const { ErrorDirect (L"Timeout"); } ! 69: }; ! 70: ! 71: struct UserAbort : public Exception ! 72: { ! 73: UserAbort (const char *srcPos) { } ! 74: void Show (HWND parent) const { } ! 75: }; ! 76: } ! 77: ! 78: #define throw_sys_if(condition) do { if (condition) throw SystemException(); } while (false) ! 79: ! 80: ! 81: #endif // TC_HEADER_Common_Exception
This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.