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.
共 1 个关于本帖的回复 最后回复于 2013-8-16 16:15