Vous ne pouvez pas sélectionner plus de 25 sujets Les noms de sujets doivent commencer par une lettre ou un nombre, peuvent contenir des tirets ('-') et peuvent comporter jusqu'à 35 caractères.

108 lignes
4.6 KiB

  1. unit uutlExceptions;
  2. {$mode objfpc}{$H+}
  3. interface
  4. uses
  5. Classes, SysUtils;
  6. type
  7. ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
  8. EutlException = class(Exception);
  9. ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
  10. EutlInvalidOperation = class(Exception);
  11. ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
  12. EutlOutOfRange = class(EutlException)
  13. private
  14. fMin: Integer;
  15. fMax: Integer;
  16. fIndex: Integer;
  17. public
  18. property Min: Integer read fMin;
  19. property Max: Integer read fMax;
  20. property Index: Integer read fIndex;
  21. constructor Create(const aIndex, aMin, aMax: Integer);
  22. constructor Create(const aMsg: String; const aIndex, aMin, aMax: Integer);
  23. end;
  24. ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
  25. EutlArgument = class(EutlException)
  26. private
  27. fArgument: String;
  28. public
  29. property Argument: String read fArgument;
  30. constructor Create(const aArgument: String);
  31. constructor Create(const aMsg, aArgument: string);
  32. end;
  33. ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
  34. EutlArgumentNil = class(EutlArgument)
  35. public
  36. constructor Create(const aArgument: String);
  37. constructor Create(const aMsg, aArgument: string);
  38. end;
  39. implementation
  40. ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
  41. //EutlOutOfRange////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
  42. ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
  43. constructor EutlOutOfRange.Create(const aIndex, aMin, aMax: Integer);
  44. begin
  45. Create('', aIndex, aMin, aMax);
  46. end;
  47. ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
  48. constructor EutlOutOfRange.Create(const aMsg: String; const aIndex, aMin, aMax: Integer);
  49. var
  50. s: String;
  51. begin
  52. fIndex := aIndex;
  53. fMin := aMin;
  54. fMax := aMax;
  55. s := Format('index (%d) out of range (%d:%d)', [fIndex, fMin, fMax]);
  56. if (aMsg <> '') then
  57. s := s + ': ' + aMsg;
  58. inherited Create(s);
  59. end;
  60. ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
  61. //EutlArgument//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
  62. ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
  63. constructor EutlArgument.Create(const aArgument: String);
  64. begin
  65. inherited Create(aArgument + ' is not valid');
  66. fArgument := aArgument;
  67. end;
  68. ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
  69. constructor EutlArgument.Create(const aMsg, aArgument: string);
  70. begin
  71. inherited Create(aMsg);
  72. fArgument := aArgument;
  73. end;
  74. ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
  75. //EutlArgumentNil///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
  76. ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
  77. constructor EutlArgumentNil.Create(const aArgument: String);
  78. begin
  79. inherited Create('argument nil: ' + aArgument, aArgument);
  80. end;
  81. ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
  82. constructor EutlArgumentNil.Create(const aMsg, aArgument: string);
  83. begin
  84. inherited Create(aMsg, aArgument);
  85. end;
  86. end.