研发埠

标题: [Oracle interview]What is the basic difference between the 2 approaches to exception handling. [打印本页]

作者: 姜青林    时间: 2013-8-16 16:11
标题: [Oracle interview]What is the basic difference between the 2 approaches to exception handling.
1> try catchblock and2> specifying the candidate exceptions in thethrows clause?When should you use which approach?
作者: 胡一搏    时间: 2013-8-16 16:15
In the first approach as a programmer ofthe method, you urself are dealing with the exception. This is fine if you arein a best position to decide should be done in case of an exception. Whereas ifit is not the responsibility of the method to deal with it's own exceptions,then do not use this approach. In this case use the second approach. In thesecond approach we are forcing the caller of the method to catch theexceptions, that the method is likely to throw. This is often the approachlibrary creators use. They list the exception in the throws clause and we mustcatch them. You will find the same approach throughout the java libraries weuse.




欢迎光临 研发埠 (http://bbs.yanfabu.com/) Powered by Discuz! X3.2