Why do you have to write throws exception in a class definition?

前端 未结 9 1152
逝去的感伤
逝去的感伤 2020-12-31 09:04

Coming from C#, I just don\'t get this \'throws exception\' that is written after a class/method definition:

public void Test() throws Exception
         


        
9条回答
  •  隐瞒了意图╮
    2020-12-31 10:00

    You have to write it in the case that the exceptions thrown are checked exceptions, which mean that it is the explicit responsibility of the caller to catch or rethrow the exception.

提交回复
热议问题