Thread View: borland.public.cppbuilder.internet.socket
3 messages
3 total messages
Started by mike
Tue, 10 Aug 2004 14:41
Exception Handling
Author: mike
Date: Tue, 10 Aug 2004 14:41
Date: Tue, 10 Aug 2004 14:41
43 lines
1898 bytes
1898 bytes
Could someone explain to me how to handle an exception when trying to open a
connection from a TClientSocket.
Heres what is happening;
I issued the following.
try
{
Form1->ClientSocket1->Open()
;
;
}
catch (...)
{
ShowMessage("Error");
}
Now I have purposly placed an invalid host into the Form1->ClientSocket1 so
that an exception will occur, and it does.
I also have the Error Event returning 0 if I get an error.
So what happens is this.
The first time I issue the open command, the Disconnect event is fired, and
then the Exception displays a message. No error even is fired.
If I issue the open command again, no Disconnect event is fired, an Error
event is fired, No Exception is fired.
If I repeat the open again, the first condition occurs again.
So I don't understand how to catch the exception, or why the actions are
different between the first open and the second open.
Can someone help me with this.
Thanks for any information.
Mike
Re: Exception Handling
Author: Remy Lebeau (TeamB)
Date: Tue, 10 Aug 2004 17:23
Date: Tue, 10 Aug 2004 17:23
18 lines
1560 bytes
1560 bytes
"mike" <mfbrowne@earthlink.net> wrote in message news:4118e06b@newsgroups.borland.com... > Could someone explain to me how to handle an exception > when trying to open a connection from a TClientSocket. If you are using the ClientSocket in non-blocking mode then you can't use exception handling when calling Open() as any exception thrown will be delayed, thrown long after Open() returns and your exception handling is exited. You should use the OnError event to catch errors, and you can optionally then set the ErrorCode parameter to 0 to prevent exceptions from being thrown at all. Otherwise, use the ClientSocket in blocking mode instead. Gambit
Re: Exception Handling
Author: mike
Date: Tue, 10 Aug 2004 21:49
Date: Tue, 10 Aug 2004 21:49
38 lines
2163 bytes
2163 bytes
Remy, I do have the on error event defined, however the client socket does not create an on error event the first time the open is called with an invalid host. It does the second time it is called, but not the third and so on. So if I use the Client Socket in blocking mode, do I have to create the thread and such as with a blocking ServerSocket. If so do you have sample code that shows what is required. Thanks Mike "Remy Lebeau (TeamB)" <gambit47.no.spam@no.spam.yahoo.com> wrote in message news:4119046a$1@newsgroups.borland.com... > > "mike" <mfbrowne@earthlink.net> wrote in message > news:4118e06b@newsgroups.borland.com... > > > Could someone explain to me how to handle an exception > > when trying to open a connection from a TClientSocket. > > If you are using the ClientSocket in non-blocking mode then you can't use > exception handling when calling Open() as any exception thrown will be > delayed, thrown long after Open() returns and your exception handling is > exited. You should use the OnError event to catch errors, and you can > optionally then set the ErrorCode parameter to 0 to prevent exceptions from > being thrown at all. > > Otherwise, use the ClientSocket in blocking mode instead. > > > Gambit > >
Thread Navigation
This is a paginated view of messages in the thread with full content displayed inline.
Messages are displayed in chronological order, with the original post highlighted in green.
Use pagination controls to navigate through all messages in large threads.
Back to All Threads