ttryfin4.pp 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111
  1. { %RESULT=217 }
  2. {****************************************************************}
  3. { CODE GENERATOR TEST PROGRAM }
  4. { By Carl Eric Codere }
  5. {****************************************************************}
  6. { NODE TESTED : secondtryfinally() }
  7. { secondraise() }
  8. {****************************************************************}
  9. { PRE-REQUISITES: secondload() }
  10. { secondassign() }
  11. { secondtypeconv() }
  12. { secondtryexcept() }
  13. { secondcalln() }
  14. { secondadd() }
  15. {****************************************************************}
  16. { DEFINES: }
  17. { FPC = Target is FreePascal compiler }
  18. {****************************************************************}
  19. {****************************************************************}
  20. program ttryfin4;
  21. {$ifdef fpc}
  22. {$mode objfpc}
  23. {$endif}
  24. Type
  25. TAObject = class(TObject)
  26. a : longint;
  27. end;
  28. TBObject = Class(TObject)
  29. b : longint;
  30. end;
  31. { The test cases were taken from the SAL internal architecture manual }
  32. procedure fail;
  33. begin
  34. WriteLn('Failure.');
  35. halt(1);
  36. end;
  37. var
  38. global_counter : integer;
  39. Procedure raiseanexception;
  40. Var A : TAObject;
  41. begin
  42. { Writeln ('Creating exception object');}
  43. A:=TAObject.Create;
  44. { Writeln ('Raising with this object');}
  45. raise A;
  46. { this should never happen, if it does there is a problem! }
  47. RunError(255);
  48. end;
  49. procedure IncrementCounter(x: integer);
  50. begin
  51. Inc(global_counter);
  52. end;
  53. procedure DecrementCounter(x: integer);
  54. begin
  55. Dec(global_counter);
  56. end;
  57. { }
  58. Procedure DoTryFinallyOne;
  59. var
  60. failed : boolean;
  61. begin
  62. Write('Try..Finally nested block with exception rise in finally block...');
  63. global_counter:=0;
  64. failed:=true;
  65. Try
  66. Try
  67. IncrementCounter(global_counter);
  68. IncrementCounter(global_counter);
  69. finally
  70. RaiseAnException;
  71. end;
  72. finally
  73. if global_counter = 2 then
  74. failed :=false;
  75. if failed then
  76. fail
  77. else
  78. WriteLn('Success!');
  79. end;
  80. end;
  81. Begin
  82. DoTryFinallyOne;
  83. end.
  84. {
  85. $Log$
  86. Revision 1.2 2002-09-07 15:40:56 peter
  87. * old logs removed and tabs fixed
  88. Revision 1.1 2002/08/03 11:05:14 carl
  89. + exception handling testing
  90. (still missing raise / on node testing)
  91. }