Link to home
Start Free TrialLog in
Avatar of fischermx
fischermxFlag for Mexico

asked on

How to shutp Delphi ADO exceptions?

So, I have this simple code:

    try
      Table1.Post;
    except

    end;

And I expect, that no matter what happen on the Post even, i get no errors and move on. Since I have this in a loop (of course I will add some more logic later for the real app).

But, I still getting a message box with the error.
And I don't get it why. I'm running this outside Delphi, so there's nothing to change in the debugger options (which I already tried anyway).

I'm using Delphi 5 and Ado components.

Any idea?

Avatar of senad
senad
Flag of Slovenia image

remove try and except ....
or ...
except
          try Post;
except
end;
What happens if you put an "on E: Exception..." handler in to your except, does that kill the error?

Outside of that, are you sure this is the code generating/showing the error?

try
  Table1.Post;
except
  on E: Exception do
    begin
      //eat the error
    end;
end;

Open in new window

you do not normally use try except in posting to tables because they have their own error routines.
but if you generate error then you must know what the error is...
Avatar of fischermx

ASKER

@senad:
Thanks for your effort in asking this, but your answer is... well, I don't know.

@irishbuddah:
Thanks for your answer. I actually have my code the exact way you have it, and I still get an error.
Hi fischermx,
  You have to know which error raised, so this code may help you
  try
    Self.ADOTable1.Post;
  except
    ShowMessage(IntToStr(Self.ADOConnection1.Errors[0].NativeError) + #13 +
                             Self.ADOConnection1.Errors[0].Description);
  end;

also you may use "NativeError" to trap the errors

Regards,
  Khalid
ASKER CERTIFIED SOLUTION
Avatar of irishbuddha
irishbuddha
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
You are right. The error was not the post, I just couldn't see it.
As I told, this code was a loop.
So, at the top, when a new insert was attempted, that was the code that raised the error.

I just added "Table1.Cancel" in my except section and all worked fine.

Thanks!