Exceptions.h 5.2 KB

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