开发者

JDBC and SQLException

I am having a Java class with several methods like this

public void someMethod (Collection<object&g开发者_StackOverflowt; objects) throws Exception

This program sometimes throws java.sql.SQLException like a Oracle deadlock but on the serverside i dont see a tracefile.

Is it advisiable to modify the method signatures to something more specific like

public void someMethod (Collection<object> objects) throws SQLException

and then in the method try the prepared statements in try catch block would it help to catch the actual exception


Declaring a method as throws Exception isn't good practice. You should be specific about what exceptions your method throws, so throws SQLException is better and more descriptive.

Your try/catch block around that method call will work regardless of whether you use throws Exception or throws SQLException. If you need to trap the deadlock, then catch the SQLException and handle it there.

If you don't handle it there, then the exception will bubble up the stack until it is either caught somewhere, or the program (or thread) exits.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜