forked from gabr42/OmniThreadLibrary
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathOtl.Parallel.Errors.pas
70 lines (55 loc) · 2.08 KB
/
Otl.Parallel.Errors.pas
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
unit Otl.Parallel.Errors;
{$I OtlOptions.inc}
interface
uses System.SysUtils;
type
TParallelException = class( Exception)
public
FErrCode: integer;
constructor Create( ErrCode: integer; const Args: array of const); overload;
constructor Create( ErrCode: integer); overload;
end;
const
EIsSignalledNotSupported = 1;
ESignalCountUpDownRange = 2;
ECannotDestroySynchroFactory = 3;
ECompositeNeedsOneFactor = 4;
EOnlyModularCombinable = 5;
ECompositeSynchroMixedBag = 6;
ParallelExceptionMessages: array[ 1 .. 10 ] of record ErrCode: integer; MsgFmt: string end = (
(ErrCode: EIsSignalledNotSupported; MsgFmt:'isSignalled() not supported on this class.'),
(ErrCode: ESignalCountUpDownRange; MsgFmt:'Signal() out of range for TCountUp/Down'),
(ErrCode: ECannotDestroySynchroFactory; MsgFmt:'Cannot destroy TSynchroFactory while there are still allocated synchros.'),
(ErrCode: ECompositeNeedsOneFactor; MsgFmt:'TCompositeSynchro needs at least one factor.'),
(ErrCode: EOnlyModularCombinable; MsgFmt:'TCompositeSynchro - all factors must be modular sychros.'),
(ErrCode: ECompositeSynchroMixedBag; MsgFmt:'TConditionEvent created with invalid mixed bag of direct and indirect members.'),
(ErrCode: 0; MsgFmt:''),
(ErrCode: 0; MsgFmt:''),
(ErrCode: 0; MsgFmt:''),
(ErrCode: 0; MsgFmt:'')
);
implementation
constructor TParallelException.Create(
ErrCode: integer; const Args: array of const);
var
I: integer;
MsgFmt: string;
begin
for I := Low( ParallelExceptionMessages) to High( ParallelExceptionMessages) do
begin
if ParallelExceptionMessages[I].ErrCode <> ErrCode then continue;
MsgFmt := ParallelExceptionMessages[I].MsgFmt;
break
end;
if MsgFmt = '' then
MsgFmt := Format( 'Unknown error (%d)', [ErrCode])
else if MsgFmt.Contains('%') and (Length( Args) > 0) then
MsgFmt := Format( MsgFmt, Args);
FErrCode := ErrCode;
inherited Create( MsgFmt)
end;
constructor TParallelException.Create( ErrCode: integer);
begin
Create( ErrCode, [])
end;
end.