关于iptcpclient和iptcpserver的有关问题 断开时提示connection closed gracefully 要按好多下才能关

关于iptcpclient和iptcpserver的问题 断开时提示connection closed gracefully 要按好多下才能关
关于iptcpclient和iptcpserver的问题   无论断开时client端总是提示connection   closed   gracefully   要按好多下才能关(是不是因为我加了IdAntiFreeze1的关系   但是在退出前已经改为false了)   有谁知道能够屏蔽这个exception窗口的办法   我在网上找很久也没找到相应的办法   谢谢啦

------解决方案--------------------
Indy : Connection Closed Gracefully
Connection Closed Gracefully
Author: Chad Z. Hower
Homepage: http://www.atozedsoftware.com


Many Indy users are annoyed by the EIdConnClosedGracefully exception that is raised with Indy servers, especially the HTTP and other servers. EIdConnClosedGracefully is an exception signaling that the connection has been closed by the other side intentionally. This is not the same as a broken connection which would cause a connection reset error. If the other side has closed the connection and the socket is read or written to, EIdConnClosedGracefully will be raised by Indy. This is similar to attempting to read or write to a file that has been closed without your knowledge.

In some cases this is a true exception and your code needs to handle it. In other cases (typically servers) this is a normal part of the functioning of the protocol and Indy handles this exception for you. Even though Indy catches it, when running in the IDE the debugger will be triggered first. You can simply press F9 to continue and Indy will handle the exception, but the constant stopping during debugging can be quite annoying. In the cases where Indy catches the exception, your users will never see an exception in your program unless it is run from the IDE.

Simple solution

Because the EIdConnClosedGracefully is a common exception especially with certain servers it descends from EIdSilentException. On the Language Exceptions tab of Debugger Options (Tools Menu) you can add EIdSilentException to the list of exceptions to ignore. After this is added the exceptions will still occur in the code and be handled, but the debugger will not stop the program to debug them.

Is it an error?

All exceptions are not errors. Many developers have been taught or assumed that all exceptions are errors. However this is not the case, and this is why they are called exceptions and not errors.

Exceptions are exactly that - exceptions. Delphi and C++ Builder use exceptions to handle errors in an elegant way. However exceptions have other uses besides errors as well. EAbort is one example of an exception that is not necessarily an error. Exceptions such as these are used to modify standard program flow and communicate information to a higher calling level where they are trapped. Indy uses exceptions in such a way as well.

Why is it an exception?

Many users have commented that maybe it there should be a return value to signal this condition instead of an exception. However this is the wrong approach in this case.

The EIdConnClosedGracefully is raised from a core routine, however when this routine is called it is normally several method calls deep. The EIdConnClosedGracefully is in fact an exception and needs to be trapped by the topmost caller in most cases. The proper way to handle this is an exception.

When is it an error?

When EIdConnClosedGracefully is raised in a client, it is an error and you should trap and handle this exception.

In servers it is an exception. However sometimes it is an error, and sometimes it is an exception. For many protocols this exception is part of the normal functioning of the protocol. Because of this common behavior, if you do not catch the EIdConnClosedGracefully in your server code, Indy will. It will then mark the connection as closed and stop the thread assigned to the connection. If you wish to handle this exception yourself you may, otherwise Indy will handle it and take the appropriate actions for you automatically.