Dein
Exception-Handling ist unsauber/fehlerhaft!
Delphi-Quellcode:
function IsValidID(ID: string): boolean;
begin
try
Row1 := .....
..... // ***
if not
((Ps1 = StrToInt(ID[10])) and
(Ps2 = StrToInt(ID[20])) and
(Ps3 = StrToInt(ID[28])) and
(Ps4 = StrToInt(ID[36]))) then
result := false
else
result := true;
except
exit
end;
end;
Wenn nun an der Stelle, die mit *** gekennzeichnet wurde eine
Exception auftritt ??
Du wirst niemals erfahren, was schiefgelaufen ist und ausserdem ein undefiniertes
Result erhalten.
Korrektes
Exception-Handling sieht so aus:
Delphi-Quellcode:
function IsValidID(ID:
string): boolean;
begin
try
Row1 := .....
.....
// ***
if not
((Ps1 = StrToInt(ID[10]))
and
(Ps2 = StrToInt(ID[20]))
and
(Ps3 = StrToInt(ID[28]))
and
(Ps4 = StrToInt(ID[36])))
then
result := false
else
result := true;
except
on E:
Exception do
begin
E.
Message := '
Fehler in IsValidID('+ID+'
)'#13#10+
E.
Message;
raise;
end;
end;
end;
Der Aufrufer, bekommt eine recht genaue Beschreibung, was schiefgelaufen ist.
Die
Exception wird nur abgefangen und erneut ausgelöst.