Cannot Catch TIdTCPClient "already connected" exception

Roger Alcindor
Roger Alcindor used Ask the Experts™
I am trying to catch an exception that is generated when a TCP client connection is attempted when the connection is already connected. The code that I am using us shown below.
All I get is a message on the screen  as also shown below.
How do I suppress this message and catch the exception in my code ?
I a using Embarcadero XE 10.1 berlin C++ Builder with an Indy 10 TCP client component.

void __fastcall TForm1::Button2Click(TObject *Sender)
        Memo1->Lines->Add(u"Failed to connect");

Open in new window

Already connected message
Watch Question

Do more with

Expert Office
EXPERT OFFICE® is a registered trademark of EXPERTS EXCHANGE®
It seems there is another exception raised before your code is even visited.


I think  not, the message appearance coincides with the clicking of Button2.
Interesting result you have. You assume that the Connect in line 5 is throwing an exception and you are just having trouble catching it. That may not be the case, especially since you are getting a popup saying that you are already connected. My guess is that Connect is doing a Connected check and taking an action that is not an exception.

According to this blog
"It is not possible for Connect() to exit without raising *some* exception if a connection to the server could not be established."
Assuming this to be true, then it would appear to me that you could continue communicating with the server since you are still connected. Is this assumption true in your case?

If you have source code, I would search for the string "Already connected" and see what was done to reach the usage of this string. (All this is my best guess since I have never worked with Embargo.)
I think the problem was with the compiler. After having shut-down my PC and later powering-up and running the compiler, the problem no longer exists. The exception is caught as expected and the pop-up message is no longer displayed.
Sorry for wasting your time guys.
I am using this method to periodically check (every 2 seconds) whether or not the connection is "live". Other methods such as sending NULL data
Thanks for your comments, the link to bcbjournal was interesting.

Do more with

Expert Office
Submit tech questions to Ask the Experts™ at any time to receive solutions, advice, and new ideas from leading industry professionals.

Start 7-Day Free Trial