Resetting the OnLostConnetion exception

The offical for ZeosLib 7.3 Report problems, ask for help, post proposals for the new version of Zeoslib 7.3/v8
Quick Info:
-We made two new drivers: odbc(raw and unicode version) and oledb
-GUID domain/field-defined support for FB
-extended error infos of Firebird
-performance ups are still in queue
In future some more feature will arrive, so stay tuned and don't hassitate to help
Post Reply
stoffman
Senior Boarder
Senior Boarder
Posts: 50
Joined: 03.12.2020, 06:55

Resetting the OnLostConnetion exception

Post by stoffman »

As a consumer of ZAbstractConnection I cannot prevent the exception of OnLostConnection from being raise, although I have a event handler to handle it. This forces me to handle the state of losing connection twice, first in the event handler and again in the function that led to this code path (handing the exception)

Can that be changes?


The following code is from the ZAbstractConnection unit

Code: Select all

procedure TZAbstractConnection.ConnectionLost(var AError: EZSQLConnectionLost);
var Err: EZSQLConnectionLost;
begin
  Err := AError;
  AError := nil;
  try
    CloseAllLinkedComponents;
  except end;
  try
    if Assigned(FOnLost) then
      FOnLost(Self); { I think the Err variable should be passed here}
  finally
    if Err <> nil then
      raise Err;
  end;
end;
User avatar
aehimself
Zeos Dev Team
Zeos Dev Team
Posts: 797
Joined: 18.11.2018, 17:37
Location: Hungary

Re: Resetting the OnLostConnetion exception

Post by aehimself »

To be honest this code looks perfectly fine to me, I would not change it. Just do a check in your exception handler and if it's the connectionlost -> don't do anything.
Or remove your code from the OnConnectionLost handler.
Delphi 12.2, Zeos 8 from latest GIT snapshot
Using:
- MySQL server 8.0.18; libmysql.dll 8.0.40 x64 5.7.19 x68, libmariadb.dll 3.3.11
- Oracle server 11.2.0, 12.1.0, 19.0.0; oci.dll 21.15
- MSSQL 2012, 2019; sybdb.dll FreeTDS_3102
- SQLite 3.47
marsupilami
Platinum Boarder
Platinum Boarder
Posts: 1956
Joined: 17.01.2011, 14:17

Re: Resetting the OnLostConnetion exception

Post by marsupilami »

Honestly I think that we could think about having a parameter like Handeled where true would indicate that everything is fine and we don't need to raise an exception and false means that we should raise an exception. Another option would be to name the paramaeter RaiseEcception and set it to rue by default...

But that is just an opinion. The decision is with Egonhugeist.
stoffman
Senior Boarder
Senior Boarder
Posts: 50
Joined: 03.12.2020, 06:55

Re: Resetting the OnLostConnetion exception

Post by stoffman »

@aehimself

Serious question, what is the point of having an event handler if you *must* also catch the exception? everything I can do in the event handler I can do in exception handler but not vice versa.
User avatar
aehimself
Zeos Dev Team
Zeos Dev Team
Posts: 797
Joined: 18.11.2018, 17:37
Location: Hungary

Re: Resetting the OnLostConnetion exception

Post by aehimself »

stoffman wrote: 19.02.2021, 22:18Serious question, what is the point of having an event handler if you *must* also catch the exception? everything I can do in the event handler I can do in exception handler but not vice versa.
While I see your point (and it is perfectly valid I must add!) I always considered these event handlers as "notifications" for your program (so you can change an icon of a tabsheet, disable controls, etc.), the code flow is always Try .. Except .. End in my opinion. An exception is what Jan just mentioned - if you have a Var parameter to notify the component.
In 99% of the cases I'm creating Zeos's components runtime in worker threads and I design my program flow with exceptions included... therefore I never used ANY event handlers up until now.

The exception raised in the code is probably a part of the design as ANY workflow must be broken if the connection is broken.
Delphi 12.2, Zeos 8 from latest GIT snapshot
Using:
- MySQL server 8.0.18; libmysql.dll 8.0.40 x64 5.7.19 x68, libmariadb.dll 3.3.11
- Oracle server 11.2.0, 12.1.0, 19.0.0; oci.dll 21.15
- MSSQL 2012, 2019; sybdb.dll FreeTDS_3102
- SQLite 3.47
Post Reply