日期:2014-05-20 浏览次数:21582 次
try {
} catch (StringIndexOutOfBoundsException e) {
// catch exception
}
// go no
------解决方案--------------------
你继续把这个异常抛出,在它的上级处理掉。
public void method() throws Exception
------解决方案--------------------
public void a(String weburl) throws Exception {
String html = "";
// 创建URL连接
java.net.URL url = new URL(weburl);
URLConnection uc = url.openConnection();
// 设定字符集
try {
InputStreamReader read = new InputStreamReader(uc.getInputStream(),
"UTF-8");
BufferedReader br = new BufferedReader(read);
// 读取下载网页html代码保存到字符串html中
while (true) {
String str = br.readLine();
if (str == null)
break;
html += str;
}
} catch (Exception e) {
html = "页面没有找到!";
throw e;
}
}
// 主方法调用
public void test() {
String url = "";
while(true) {
try {
a(url);
} catch(Exception e) {
}
url = url + "...";
}
}
------解决方案--------------------
把异常Catch掉 然后做处理 。。。
------解决方案--------------------
StringIndexOutOfBoundsException 是一个RuntimeException异常,可不必理会程序都会继续运行
------解决方案--------------------
异常最好到一个层统一处理,哈哈
每天回贴好习惯。。。
------解决方案--------------------
先用String 接受字符串
然后判断是否为空
空则无操作
非空则转int.