我已经为URLconnection和Parser类实现了一个try catch块,如下所示。
where ri.ross_PO_nbr = sp.PO_ID and
ri.ross_sku12) = substr(bitem_id, 1, 12)
所以,我的问题是如何根据SocketTimeOutException情况采取相应的行动,以及其他异常忽略。
谢谢,
答案 0 :(得分:2)
将更具体的异常类型放在更一般的类型之上,因此将SocketTimeoutException
catch子句置于Exception
答案 1 :(得分:2)
正如java规范所述(http://docs.oracle.com/javase/specs/jls/se7/html/jls-11.html#jls-11.2.3和http://docs.oracle.com/javase/specs/jls/se7/html/jls-14.html#jls-14.20),首先匹配,首先执行。
简单地颠倒你的catch子句:
try {
Url uri = new Url(urlString);
Parser parse = new Parser(uri);
} catch (SocketTimeOutException e) {
//I want to cache this ecption and do some thing or restart based
//if its timeout issue
//am using proxy for the network connection at JVM setting
//using setProperty
} catch (Exception e) {
//ingnore some other excpetions
}
答案 2 :(得分:1)
首先捕获SocketTimeOutException:
try {
// do stuff
} catch (SocketTimeOutException e) {
// restart or do whatever you need to do
} catch (Exception e) {
// do something else
}
答案 3 :(得分:1)
如何在一个try / catch块中捕获异常和SocketTimeOut异常?如果您不想只有一个捕获块,那么您可以这样做
try {
URI uri = new URI(urlString);
Parser parse = new Parser(uri);
} catch(Exception e) {
if (e instanceof SocketTimeoutException) {
// do something
}
}