blob: 9330f597dd571af12536df34ca2cd40bc9c89a57 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
|
{ %version=1.1}
{$IFDEF FPC}
{$MODE OBJFPC}
{$ENDIF}
program texception5;
uses
SysUtils;
type
ETestException = class(Exception)
constructor Create;
destructor Destroy; override;
end;
var
exc_destroyed: boolean;
exc : ETestException;
constructor ETestException.Create;
begin
exc_destroyed := false;
exc := Self;
end;
destructor ETestException.Destroy;
begin
inherited;
exc_destroyed := true;
end;
var
exc2: Exception;
begin
// first test, exception should not be freed
try
raise ETestException.Create;
except
exc2 := Exception(AcquireExceptionObject);
if exc <> exc2 then halt(11);
end;
if exc_destroyed then halt(12);
if exc <> exc2 then halt(13);
exc2.Free;
// second test, exception should be freed
try
raise ETestException.Create;
except
exc2 := Exception(AcquireExceptionObject);
if exc <> exc2 then halt(21);
ReleaseExceptionObject;
end;
if not exc_destroyed then halt(22);
// third test, exception should not be freed
try
raise ETestException.Create;
except
AcquireExceptionObject;
AcquireExceptionObject;
ReleaseExceptionObject;
end;
if exc_destroyed then halt(31);
// exception should be freed
try
raise ETestException.Create;
except
AcquireExceptionObject;
AcquireExceptionObject;
ReleaseExceptionObject;
ReleaseExceptionObject;
end;
if not exc_destroyed then halt(41);
// exception should be freed, refcount zeroed when re-raising
try
try
raise ETestException.Create;
except
on e: exception do begin
AcquireExceptionObject;
raise;
end;
end;
except
end;
if not exc_destroyed then halt(51);
// same as before but without explicit block
try
try
raise ETestException.Create;
except
AcquireExceptionObject;
raise;
end;
except
end;
if not exc_destroyed then halt(61);
end.
|