Exceptions.h 5.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107
  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, AnsiString & Message);
  10. AnsiString __fastcall LastSysErrorMessage();
  11. TStrings * 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, AnsiString Msg);
  20. // "copy the exception", just append message to the end
  21. __fastcall ExtException(AnsiString Msg, Exception* E);
  22. __fastcall ExtException(AnsiString Msg, AnsiString MoreMessages, AnsiString HelpKeyword = "");
  23. __fastcall ExtException(AnsiString Msg, TStrings* MoreMessages, bool Own);
  24. __fastcall virtual ~ExtException(void);
  25. __property TStrings* MoreMessages = {read=FMoreMessages};
  26. __property AnsiString HelpKeyword = {read=FHelpKeyword};
  27. inline __fastcall ExtException(const AnsiString 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 AnsiString Msg, int AHelpContext) : Sysutils::Exception(Msg, AHelpContext) { }
  30. inline __fastcall ExtException(const AnsiString 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. protected:
  34. void __fastcall AddMoreMessages(Exception* E);
  35. private:
  36. Classes::TStrings* FMoreMessages;
  37. AnsiString FHelpKeyword;
  38. };
  39. //---------------------------------------------------------------------------
  40. #define DERIVE_EXT_EXCEPTION(NAME, BASE) \
  41. class NAME : public BASE \
  42. { \
  43. public: \
  44. inline __fastcall NAME(Exception* E, AnsiString Msg) : BASE(E, Msg) { } \
  45. inline __fastcall NAME(Exception* E, int Ident) : BASE(E, Ident) { } \
  46. inline __fastcall virtual ~NAME(void) { } \
  47. inline __fastcall NAME(const AnsiString Msg, const TVarRec * Args, const int Args_Size) : BASE(Msg, Args, Args_Size) { } \
  48. inline __fastcall NAME(int Ident, const TVarRec * Args, const int Args_Size) : BASE(Ident, Args, Args_Size) { } \
  49. inline __fastcall NAME(const AnsiString Msg, int AHelpContext) : BASE(Msg, AHelpContext) { } \
  50. inline __fastcall NAME(const AnsiString Msg, const TVarRec * Args, const int Args_Size, int AHelpContext) : BASE(Msg, Args, Args_Size, AHelpContext) { } \
  51. inline __fastcall NAME(int Ident, int AHelpContext) : BASE(Ident, AHelpContext) { } \
  52. inline __fastcall NAME(PResStringRec ResStringRec, const TVarRec * Args, const int Args_Size, int AHelpContext) : BASE(ResStringRec, Args, Args_Size, AHelpContext) { } \
  53. };
  54. //---------------------------------------------------------------------------
  55. DERIVE_EXT_EXCEPTION(ESsh, ExtException);
  56. DERIVE_EXT_EXCEPTION(ETerminal, ExtException);
  57. DERIVE_EXT_EXCEPTION(ECommand, ExtException);
  58. DERIVE_EXT_EXCEPTION(EScp, ExtException); // SCP protocol fatal error (non-fatal in application context)
  59. DERIVE_EXT_EXCEPTION(EScpSkipFile, ExtException);
  60. DERIVE_EXT_EXCEPTION(EScpFileSkipped, EScpSkipFile);
  61. //---------------------------------------------------------------------------
  62. class EOSExtException : public ExtException
  63. {
  64. public:
  65. __fastcall EOSExtException();
  66. __fastcall EOSExtException(AnsiString Msg);
  67. };
  68. //---------------------------------------------------------------------------
  69. class EFatal : public ExtException
  70. {
  71. public:
  72. // fatal errors are always copied, new message is only appended
  73. __fastcall EFatal(Exception* E, AnsiString Msg);
  74. __property bool ReopenQueried = { read = FReopenQueried, write = FReopenQueried };
  75. private:
  76. bool FReopenQueried;
  77. };
  78. //---------------------------------------------------------------------------
  79. #define DERIVE_FATAL_EXCEPTION(NAME, BASE) \
  80. class NAME : public BASE \
  81. { \
  82. public: \
  83. inline __fastcall NAME(Exception* E, AnsiString Msg) : BASE(E, Msg) { } \
  84. };
  85. //---------------------------------------------------------------------------
  86. DERIVE_FATAL_EXCEPTION(ESshFatal, EFatal);
  87. //---------------------------------------------------------------------------
  88. // exception that closes application, but displayes info message (not error message)
  89. // = close on completionclass ESshTerminate : public EFatal
  90. class ESshTerminate : public EFatal
  91. {
  92. public:
  93. inline __fastcall ESshTerminate(Exception* E, AnsiString Msg, TOnceDoneOperation AOperation) :
  94. EFatal(E, Msg),
  95. Operation(AOperation)
  96. { }
  97. TOnceDoneOperation Operation;
  98. };
  99. //---------------------------------------------------------------------------
  100. #endif // Exceptions