Exceptions.h 4.5 KB

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