PostgreSQL exception handling problem
PostgreSQL exception handling problem
Hello,
Using UniDAC 7.0.1 on Delphi 10.2. Target is 32bit executable. Database is PostgreSQL 9.6.2 64bit (EDB Binaries used for installing) running on Windows 10 64bit OS.
Using try..except block to catch any error on database commands is not working. If any exception raises, it is simply, directly displayed on the screen than being catched in my except block. In other words, except blocks are never executed.
Sample application to reproduce the problem can be downloaded from here: postgresql_exception_handling.rar
If this is a feature, please advise how can I use UniDAC the right way to catch these exceptions.
Thanks & regards.
Using UniDAC 7.0.1 on Delphi 10.2. Target is 32bit executable. Database is PostgreSQL 9.6.2 64bit (EDB Binaries used for installing) running on Windows 10 64bit OS.
Using try..except block to catch any error on database commands is not working. If any exception raises, it is simply, directly displayed on the screen than being catched in my except block. In other words, except blocks are never executed.
Sample application to reproduce the problem can be downloaded from here: postgresql_exception_handling.rar
If this is a feature, please advise how can I use UniDAC the right way to catch these exceptions.
Thanks & regards.
Re: PostgreSQL exception handling problem
Hello,
You should use the UniConnection.OnError event
and to handle the exception set the Fail parameter to False;
You should use the UniConnection.OnError event
and to handle the exception set the Fail parameter to False;
Re: PostgreSQL exception handling problem
Hello,
Below code helped to solve my problem.
TDM is a TDataModule
DB is name of TUniConnection
Normally, I did not use that TUniConnection.OnError() procedure when I am working with SQL Server or SQLite. Actually, this is the first time I am using it. Is this way of error handling specific to PostgreSQL?
Thanks.
Below code helped to solve my problem.
Code: Select all
procedure TDM.DBError(Sender: TObject; E: EDAError; var Fail: Boolean);
begin
Fail := False;
end;
DB is name of TUniConnection
Normally, I did not use that TUniConnection.OnError() procedure when I am working with SQL Server or SQLite. Actually, this is the first time I am using it. Is this way of error handling specific to PostgreSQL?
Thanks.
Re: PostgreSQL exception handling problem
For this, you can check the exception class
Code: Select all
uses ..., PgErrorUni;
...
procedure TForm1.UniConnection1Error(Sender: TObject; E: EDAError;
var Fail: Boolean);
begin
if E is EPgError then
...
Re: PostgreSQL exception handling problem
Dear Alex,
I just realize that suggested usage is necessary for TUniScript exception handling. TUniQuery default executing except block without any code written for TUniConnection.OnError() procedure.
Thanks for the help.
I just realize that suggested usage is necessary for TUniScript exception handling. TUniQuery default executing except block without any code written for TUniConnection.OnError() procedure.
Thanks for the help.
Re: PostgreSQL exception handling problem
This different behavior is implemented because UniScript can execute multiple commands in a row, and even if there is an error in one of the commands, it would be possible to continue execution of other commands. If you don't want to use the global OnError event in UniConnection you can use the OnError event for each UniScript
-
- Posts: 13
- Joined: Thu 16 Aug 2018 15:54
Re: PostgreSQL exception handling problem
Sorry but no, is not clear. And is broken in the latest version
I want to ignore scripts error when active a variable UniScriptIgnoreErrors. How to do?
Cant find a correct combination for that
my code is inside a try except block.
If I use this solution, your library manages the exception showing a visual error. That not happens in previous versions.Why?
If I use the following solution Never get UniScript1Error so I can't control when it raise errors.
Please explain step by step how to be able to manage in a try exception block an unidac exception and how to make able to ignore that , as was possible in the past.
P.S. im using version 8.1.3 in Delphi RIO
I want to ignore scripts error when active a variable UniScriptIgnoreErrors. How to do?
Cant find a correct combination for that
my code is inside a try except block.
If I use this solution, your library manages the exception showing a visual error. That not happens in previous versions.Why?
Code: Select all
procedure TdmBaseLocal.UniScript1Error(Sender: TObject; E: Exception; SQL: string; var Action: TErrorAction);
begin
if UniScriptIgnoreErrors then
begin
Action := eaContinue;
end
else
begin
Action := eaException;
end;
end;
Code: Select all
procedure TdmBaseLocal.UniScript1Error(Sender: TObject; E: Exception; SQL: string; var Action: TErrorAction);
begin
if UniScriptIgnoreErrors then
begin
Action := eaContinue;
end
else
begin
Action := eaException;
end;
end;
procedure TdmBaseLocal.UniConnectionError(Sender: TObject; E: EDAError; var Fail: Boolean);
begin
Fail := False;
end;
P.S. im using version 8.1.3 in Delphi RIO
-
- Posts: 13
- Joined: Thu 16 Aug 2018 15:54
Re: PostgreSQL exception handling problem
I find the correct code to do that work as work in the past
Code: Select all
procedure TdmBaseLocal.UniConnectionError(Sender: TObject; E: EDAError; var Fail: Boolean);
begin
Fail := True;
end;
procedure TdmBaseLocal.UniScript1Error(Sender: TObject; E: Exception; SQL: string; var Action: TErrorAction);
begin
if UniScriptIgnoreErrors then
begin
Action := eaContinue;
end
else
begin
Action := eaFail;
end;
end;