【发布时间】:2011-10-06 08:12:24
【问题描述】:
我正在使用 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 ?
}
【问题讨论】: