Any big reasons to define custome exceptions in Java?
Share
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
Two reasons immediately spring to mind:
try { ... } catch (Exception e) { ... }– having your own subclasses lets you treat distinct exception cases separately. (Such as the difference between not having permissions to run a report, and the report execution failing).AlreadyLoggedInException, say, that exception can have a method to retrieve the IP address from which the other session was started. Or anAccountLimitExceededExceptioncould contain the current account limit. Extra information in the exception allows you to potentially take a more well-informed response when catching it.