Exceptions.h 6.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127
  1. //---------------------------------------------------------------------------
  2. #ifndef ExceptionsH
  3. #define ExceptionsH
  4. #include <Classes.hpp>
  5. #include <SysUtils.hpp>
  6. #include <SysInit.hpp>
  7. #include <System.hpp>
  8. //---------------------------------------------------------------------------
  9. bool __fastcall ExceptionMessage(Exception * E, UnicodeString & Message);
  10. UnicodeString __fastcall LastSysErrorMessage();
  11. TStrings * __fastcall ExceptionToMoreMessages(Exception * E);
  12. //---------------------------------------------------------------------------
  13. enum TOnceDoneOperation { odoIdle, odoDisconnect, odoShutDown };
  14. //---------------------------------------------------------------------------
  15. class ExtException : public Sysutils::Exception
  16. {
  17. public:
  18. __fastcall ExtException(Exception* E);
  19. __fastcall ExtException(Exception* E, UnicodeString Msg, UnicodeString HelpKeyword = L"");
  20. // "copy the exception", just append message to the end
  21. __fastcall ExtException(UnicodeString Msg, Exception* E, UnicodeString HelpKeyword = L"");
  22. __fastcall ExtException(UnicodeString Msg, UnicodeString MoreMessages, UnicodeString HelpKeyword = "");
  23. __fastcall ExtException(UnicodeString Msg, TStrings* MoreMessages, bool Own, UnicodeString HelpKeyword = "");
  24. __fastcall virtual ~ExtException(void);
  25. __property TStrings* MoreMessages = {read=FMoreMessages};
  26. __property UnicodeString HelpKeyword = {read=FHelpKeyword};
  27. inline __fastcall ExtException(const UnicodeString Msg, const TVarRec * Args, const int Args_Size) : Sysutils::Exception(Msg, Args, Args_Size) { }
  28. inline __fastcall ExtException(int Ident, const TVarRec * Args, const int Args_Size)/* overload */ : Sysutils::Exception(Ident, Args, Args_Size) { }
  29. inline __fastcall ExtException(const UnicodeString Msg, int AHelpContext) : Sysutils::Exception(Msg, AHelpContext) { }
  30. inline __fastcall ExtException(const UnicodeString Msg, const TVarRec * Args, const int Args_Size, int AHelpContext) : Sysutils::Exception(Msg, Args, Args_Size, AHelpContext) { }
  31. inline __fastcall ExtException(int Ident, int AHelpContext)/* overload */ : Exception(Ident, AHelpContext) { }
  32. inline __fastcall ExtException(PResStringRec ResStringRec, const TVarRec * Args, const int Args_Size, int AHelpContext)/* overload */ : Sysutils::Exception(ResStringRec, Args, Args_Size, AHelpContext) { }
  33. virtual ExtException * __fastcall Clone();
  34. protected:
  35. void __fastcall AddMoreMessages(Exception* E);
  36. private:
  37. Classes::TStrings* FMoreMessages;
  38. UnicodeString FHelpKeyword;
  39. };
  40. //---------------------------------------------------------------------------
  41. #define DERIVE_EXT_EXCEPTION(NAME, BASE) \
  42. class NAME : public BASE \
  43. { \
  44. public: \
  45. inline __fastcall NAME(Exception* E, UnicodeString Msg, UnicodeString HelpKeyword = L"") : BASE(E, Msg, HelpKeyword) { } \
  46. inline __fastcall NAME(Exception* E, int Ident) : BASE(E, Ident) { } \
  47. inline __fastcall virtual ~NAME(void) { } \
  48. inline __fastcall NAME(const UnicodeString Msg, const TVarRec * Args, const int Args_Size) : BASE(Msg, Args, Args_Size) { } \
  49. inline __fastcall NAME(int Ident, const TVarRec * Args, const int Args_Size) : BASE(Ident, Args, Args_Size) { } \
  50. inline __fastcall NAME(const UnicodeString Msg, int AHelpContext) : BASE(Msg, AHelpContext) { } \
  51. inline __fastcall NAME(const UnicodeString Msg, const TVarRec * Args, const int Args_Size, int AHelpContext) : BASE(Msg, Args, Args_Size, AHelpContext) { } \
  52. inline __fastcall NAME(int Ident, int AHelpContext) : BASE(Ident, AHelpContext) { } \
  53. inline __fastcall NAME(PResStringRec ResStringRec, const TVarRec * Args, const int Args_Size, int AHelpContext) : BASE(ResStringRec, Args, Args_Size, AHelpContext) { } \
  54. virtual ExtException * __fastcall Clone() { return new NAME(this, L""); } \
  55. };
  56. //---------------------------------------------------------------------------
  57. DERIVE_EXT_EXCEPTION(ESsh, ExtException);
  58. DERIVE_EXT_EXCEPTION(ETerminal, ExtException);
  59. DERIVE_EXT_EXCEPTION(ECommand, ExtException);
  60. DERIVE_EXT_EXCEPTION(EScp, ExtException); // SCP protocol fatal error (non-fatal in application context)
  61. DERIVE_EXT_EXCEPTION(EScpSkipFile, ExtException);
  62. DERIVE_EXT_EXCEPTION(EScpFileSkipped, EScpSkipFile);
  63. //---------------------------------------------------------------------------
  64. class EOSExtException : public ExtException
  65. {
  66. public:
  67. __fastcall EOSExtException();
  68. __fastcall EOSExtException(UnicodeString Msg);
  69. };
  70. //---------------------------------------------------------------------------
  71. class EFatal : public ExtException
  72. {
  73. public:
  74. // fatal errors are always copied, new message is only appended
  75. __fastcall EFatal(Exception* E, UnicodeString Msg, UnicodeString HelpKeyword = "");
  76. __property bool ReopenQueried = { read = FReopenQueried, write = FReopenQueried };
  77. virtual ExtException * __fastcall Clone();
  78. private:
  79. bool FReopenQueried;
  80. };
  81. //---------------------------------------------------------------------------
  82. #define DERIVE_FATAL_EXCEPTION(NAME, BASE) \
  83. class NAME : public BASE \
  84. { \
  85. public: \
  86. inline __fastcall NAME(Exception* E, UnicodeString Msg, UnicodeString HelpKeyword = "") : BASE(E, Msg, HelpKeyword) { } \
  87. virtual ExtException * __fastcall Clone() { return new NAME(this, L""); } \
  88. };
  89. //---------------------------------------------------------------------------
  90. DERIVE_FATAL_EXCEPTION(ESshFatal, EFatal);
  91. //---------------------------------------------------------------------------
  92. // exception that closes application, but displays info message (not error message)
  93. // = close on completion
  94. class ESshTerminate : public EFatal
  95. {
  96. public:
  97. inline __fastcall ESshTerminate(Exception* E, UnicodeString Msg, TOnceDoneOperation AOperation) :
  98. EFatal(E, Msg),
  99. Operation(AOperation)
  100. { }
  101. virtual ExtException * __fastcall Clone();
  102. TOnceDoneOperation Operation;
  103. };
  104. //---------------------------------------------------------------------------
  105. class ECallbackGuardAbort : public EAbort
  106. {
  107. public:
  108. __fastcall ECallbackGuardAbort();
  109. };
  110. //---------------------------------------------------------------------------
  111. Exception * __fastcall CloneException(Exception * Exception);
  112. void __fastcall RethrowException(Exception * E);
  113. UnicodeString __fastcall GetExceptionHelpKeyword(Exception * E);
  114. UnicodeString __fastcall MergeHelpKeyword(const UnicodeString & PrimaryHelpKeyword, const UnicodeString & SecondaryHelpKeyword);
  115. bool __fastcall IsInternalErrorHelpKeyword(const UnicodeString & HelpKeyword);
  116. //---------------------------------------------------------------------------
  117. #endif // Exceptions