Why should we write custom exception classes in Java

前端 未结 6 1784
执念已碎
执念已碎 2020-12-19 03:49

What is the purpose of writing custom exception classes when mostly what it does is same. For eg, NullPointerException:

class NullPointerException extends Ru         


        
6条回答
  •  醉酒成梦
    2020-12-19 04:17

    The main purpose would be identify the custom / app-specific errors. You can also provide some additional methods there. For eg, we have custom exceptions that return custom messages, and also extracts cause and location from the stack trace.

提交回复
热议问题