Page 1 of 1

How to make ODAC throw an exception

Posted: Fri 09 Jul 2010 11:42
by Lass.Mint
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

Posted: Fri 09 Jul 2010 15:16
by bork
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).

Posted: Tue 13 Jul 2010 16:57
by Lass.Mint
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

Posted: Wed 14 Jul 2010 15:00
by bork
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.

Posted: Mon 26 Jul 2010 11:47
by Lass.Mint
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 :)