Dav*_*veM -3 java eclipse try-catch-finally
我有一些代码会抛出一个潜在的错误,我会抓住这些,然后跳进一个finally块,这里是'伪'形式.
private boolean myMethod(ResultSet rs1, ResultSet rs2){
Vector<String> temp = new Vector<String>();
try{
//add info into temp while condition is true
while(true){temp.add(information);}//potentially throws an SQL error
//test my temo object for some codition
if(false){throw InternalError();}
}catch (SQLException e){
//send error message
}
catch (InternalError e){
//send error message
}
finally{
//whatever happens I need to send a result of some sort!
if(temp.size() > 1){
//create class member variable from this info
}
//send a message explaining that an error has occurred.
//this is the message to say if things have worked or not, so as the
//calling code can handle an re-run this method until this value returns true.
return booleanValue
}//end finally
}//end method
Run Code Online (Sandbox Code Playgroud)
我不确定此错误消息在此实例中的确切含义.
我通常在任何抛出它们的方法中处理任何异常,如果我在这个实例中抛出而不是处理异常,并捕获自定义异常中的两个错误?
我发出的前两条消息主要用于开发目的,因为我必须处理它们.我的finally块中的消息最终将包含给用户的消息,要求他们确认情况,进行修改,中止或改变我们如何处理这种情况.
我该怎么做才能"删除"编译器消息.我不喜欢在我的代码中抑制警告,因为我不喜欢暗示我可能在链中进一步抑制其他东西,并且抑制是针对整个方法,我不能为此添加它小块代码.
对我的情况有什么建议吗?
提前致谢.
edit1:为了反映评论,抱歉忘了把正确的返回类型(愚蠢的错误)与if(test){}右括号相同.
PS.对于那些已经'downvoted'的人,你可以发表评论并给我一个机会在downvoting之前进行编辑.谢谢.同样在我的代码中,这些东西并没有给我带来任何问题,这是一个在发布过程中大脑和手指之间存在"一个'quertyscript故障'的情况.
如果您已经格式化了代码,那么您会看到该finally子句位于a中catch,并且未链接到任何try子句.
你应该有
try {
} catch {
} finally {
}
Run Code Online (Sandbox Code Playgroud)
并不是
try {
} catch {
finally {
}
}
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
3752 次 |
| 最近记录: |