Extending Exception/RunTimeException in java?

前端 未结 5 1937
失恋的感觉
失恋的感觉 2020-12-04 11:15

I have below classes.

public class ValidationException extends RuntimeException {


}

and

public class ValidationException          


        
5条回答
  •  离开以前
    2020-12-04 12:14

    If you extend RuntimeException, you don't need to declare it in the throws clause (i.e. it's an unchecked exception). If you extend Exception, you do (it's a checked exception).

    Some people argue that all exceptions should extend from RuntimeException, but if you want to force the user to handle the exception, you should extend Exception instead.

提交回复
热议问题