How to make ODAC throw an exception

Discussion of open issues, suggestions and bugs regarding ODAC (Oracle Data Access Components) for Delphi, C++Builder, Lazarus (and FPC)
Post Reply
Lass.Mint
Posts: 13
Joined: Fri 18 Jun 2010 15:03

How to make ODAC throw an exception

Post by Lass.Mint » Fri 09 Jul 2010 11:42

Hi everyone.

I have a problem with ODAC exception handling.

I have a special error message dialog where I show a "user understandable" message and in a detail field I put the exception message. The dialog is displayed in the exception handler like this:

Code: Select all

try
  //Execute some SQL
except
  on E: Exception do
    showErrorDialog("Error Message for user", E.Message);
end;
In my first try with ODAC my error dialog was never shown, but instead a very simple dialog with the exception message was shown.
I found out that I had to implement an error handler (TDAConnectionErrorEvent). I set the "Fail" parameter to false and thought that the exception is now raised properly. But in my dialog, all that was displayed was "Operation aborted" because an EAbortError is raised.

Is there any way to make ODAC just raise the exception? I want to catch the exception in my GUI and display the error dialog like in the example above. I also use the same technique to write exceptions to my log file.

Thanks in advance,
Eric

bork
Devart Team
Posts: 649
Joined: Fri 12 Mar 2010 07:55

Post by bork » Fri 09 Jul 2010 15:16

Hello

I created an empty application, added a button and added the following code on the button click event:

Code: Select all

procedure TForm1.Button1Click(Sender: TObject);
begin
  try
    OraSession1.ExecSQL('delete * from non_exist_table', []);
  except
    on E: Exception do
      ShowMessage('My error message');
  end;
end;
Exception was raised and message dialog was shown.

If in your case an error message is not shown then please provide me the SQL statement that you are trying to execute and the ODAC component that you are using for executing this SQL.

Also please specify exact ODAC version that you are using (for example 6.90.0.59).

Lass.Mint
Posts: 13
Joined: Fri 18 Jun 2010 15:03

Post by Lass.Mint » Tue 13 Jul 2010 16:57

Hi Bork,
thanks for the answer.

The problem I described is happening with any SQL I execute that fails for example 'select foo from bar'. I'm using ODAC version 6.90.0.58.

As I'm not in the office today I will check your solution tommorow and get back here with my results.

Btw: Are there any parameters that I may have set up incorrectly that could create the behavior I described?

Thanks and Regards,
Eric

bork
Devart Team
Posts: 649
Joined: Fri 12 Mar 2010 07:55

Post by bork » Wed 14 Jul 2010 15:00

Hello

The exception is not raised in this case only if you use TOraScript (see section Reference -> DAScript -> Classes -> TDAScript Class -> Events -> OnError of the ODAC help). If you use TOraQuery, TSmartQuery, TOraSQL, TOraSession.ExecSQL, then the exception will always be raised in case of error regardless of any parameters or options.

I am waiting for the result of checking my solution.

Lass.Mint
Posts: 13
Joined: Fri 18 Jun 2010 15:03

Post by Lass.Mint » Mon 26 Jul 2010 11:47

Hi bork,
the solution you proposed works if I create a new, empty application. But in our companies software it does not. So the problem seems to be in our implementation. I will investigate in more detail and get back here if I find out anything.

Thanks so far for the quick help :)

Post Reply