0

Suppose the following code:

public static void somMethod() throws IOException { try { // some code that can throw an IOException and no other checked exceptions } catch (IOException e) { // some stuff here -- no exception thrown in this block } } 

someMethod throws an IOException, and no other checked exception, and handles that exception itself.

What exactly

throws IOException 

in its declaration is bringing in? From what I know, it is making it possible for the methods calling someMethod() handle that IOException themselves.

is anything else happening here?

5
  • 1
    If the catch block is rethrowing the exception, the throws IOException is necessary for any code calling the method. Commented Aug 31, 2013 at 20:51
  • no, the catch stat. is clear. Commented Aug 31, 2013 at 20:51
  • ..but thx for the point. Commented Aug 31, 2013 at 20:52
  • I wish I can answer this, but I can't understand your question. Could you please rephrase or add more detail? Thanks. Commented Aug 31, 2013 at 20:54
  • @Nayuki Minase rather asking for verification-- not a Q per se. as plain as it seems, nothing behind it. Commented Aug 31, 2013 at 20:58

1 Answer 1

2

If the catch block doesn't throw IOException, the throws IOException part in the method signature is not necessary. And also, every time the someMethod() is invoked, there has to be provided a catch block for a possible exception that actually never occurs.

Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.