ttryfin3.pp 2.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091
  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 ttryfin3;
  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 with exception rise in finally block...');
  63. global_counter:=0;
  64. failed:=true;
  65. Try
  66. IncrementCounter(global_counter);
  67. DecrementCounter(global_counter);
  68. finally
  69. RaiseAnException;
  70. end;
  71. end;
  72. Begin
  73. DoTryFinallyOne;
  74. end.