我使用java连接到http服务器。一切皆好。当然,我收到了例外(SocketTimeoutException
,ConnectException
,IOException
)。但我的问题是(例如)ConnectException
发生时,应用程序停滞不前。我不能继续在程序的其他部分...我试过"return ..", System.exit
(但我不想退出应用程序)。任何想法 ?如何退出捕捉异常
骨架PROG看起来是这样的:
boolean metod_to_check_http_server(){
try{
Create_connection(URL);
Set_Time_Out(3000);
open_HTTP_Connection();
Close_Connection();
return true; // All this part is fine...
}
catch (EXCEPTIONS)
{ // Here I know I have connection problem
// how could I return to main prog from here ?
// return false ? not work...
// System.exit(..); // too violent !
// so ?
}
它总是最基本的东西卡住了。我看到了doc中的“finally”块,但没有写得很好。当然,它的工作。谢谢你们所有人去除我眼中的阴影。 – Zamboo