Exceptions.h 4.3 KB

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