Why user defined exception classes are preferred/important in java?

前端 未结 3 381
后悔当初
后悔当初 2021-01-20 06:09

When we have System defined exception classes in Java, then why there is need to make user defined exception classes? Because my teacher told me to make Exception classes in

3条回答
  •  谎友^
    谎友^ (楼主)
    2021-01-20 06:41

    Because the existing exceptions may not be suitable for your situation. By creating your own exception you can make it easier to understand why the exception is thrown and it will stand out better than if you were using an existing exception.

提交回复
热议问题