APS NZ
asked on
try ... except ignored
I am processing data from a stringgrid into a table and have the code block below which should give a silent error and add the detail to my log file, but instead the program stops if it encounters a duplicate record and throws a standard error message, then will not process any more data.
The problem is inconsistent, because I use try ... except blocks in other parts of the code, and they work as expected - throwing a silent error and adding detail to the log.
I am not running inside the IDE. Am I missing something ....?
procedure TForm1.AddToCCOExtras(Cde: String; ACol: Integer);
begin
If FindExtrasCode(Cde) then
begin
Table1.Append;
With Table1 do
begin
AddHeader;
AddTempDetails;
AddExtrasCode(ACol);
end;
If Not Missing then
begin
try
Table1.Post;
except
AddToErrorLog(' Duplicate person:');
end;
end;
end else AddToErrorLog(' Code '+Cde+' missing from JobOrder ');
end;
The problem is inconsistent, because I use try ... except blocks in other parts of the code, and they work as expected - throwing a silent error and adding detail to the log.
I am not running inside the IDE. Am I missing something ....?
procedure TForm1.AddToCCOExtras(Cde:
begin
If FindExtrasCode(Cde) then
begin
Table1.Append;
With Table1 do
begin
AddHeader;
AddTempDetails;
AddExtrasCode(ACol);
end;
If Not Missing then
begin
try
Table1.Post;
except
AddToErrorLog(' Duplicate person:');
end;
end;
end else AddToErrorLog(' Code '+Cde+' missing from JobOrder ');
end;
ASKER
Thanks for the reply ThievingSix. I have just tried that but it did not work.
It might be something that you can't prevent then, such as an error from a dll. Not sure though, maybe someone else will have more information.
deleting a question is not something which will help others.
so post a comment of how you did it and accept your own comment
so post a comment of how you did it and accept your own comment
Try adjusting the try bit to this instead, does it work?
if not Missing then
try
Table1.Post;
except
AddToErrorLog(' Duplicate person:');
end;
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Something like this:
Try
Try
Table1.Post;
Except
AddToErrorLog(' Duplicate person:');
end;
Finally
end;