Link to home
Start Free TrialLog in
Avatar of jbanafato
jbanafato

asked on

TClientSocket Exceptions

Hey everyone.  I'm working with a TClientSocket component.  Here's my problem:

var Connection: TClientSocket
----
...
try
  Connection.Open;
except
  on EAsyncSocketError do ShowMessage('Error.');
end;
...
---

This construction will not catch exceptions thrown by the Connection object.  Any ideas why?  Is this a documented thing?  Thanks for any help.

-Joe
Avatar of Cesario Lababidi
Cesario Lababidi
Flag of Germany image

Hi jbanafato,

To catch the exception use the ClientSocketError Event :

procedure TForm1.ClientSocket1Error(Sender: TObject;
  Socket: TCustomWinSocket; ErrorEvent: TErrorEvent;
  var ErrorCode: Integer);
begin
  ErrorCode := 0;
  // If you dont set the ErrorCode to 0 so you got an      exception
end;

Best Regards

Cesario
Avatar of jbanafato
jbanafato

ASKER

Excellent, exactly what I'm looking for.  That should fix my problem.  Thank you very much.

-Joe
ASKER CERTIFIED SOLUTION
Avatar of Cesario Lababidi
Cesario Lababidi
Flag of Germany 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