What happens if a method throws an exception that was not specified in the method declaration with “throws”

前端 未结 6 1335
忘掉有多难
忘掉有多难 2021-01-01 11:27

I\'ve never used the \"throws\" clause, and today a mate told me that I had to specify in the method declaration which exceptions the method may throw. However, I\'ve been u

6条回答
  •  天涯浪人
    2021-01-01 12:13

    Java throws keyword,

    • Java throws keyword is used to declare an exception.
    • throws is followed by class.
    • Checked exception can be propagated with throws.
    • It provides information to the caller of the method about the exception.

    throws example,

    void m()throws ArithmeticException{  
        //method code  
    }  
    

提交回复
热议问题