1.

When Is Custom Exception Class Needed? How To Create A Custom Exception Class?

Answer»

According to Java DOCS, you should write your own exception classes if you ANSWER yes to any of the FOLLOWING questions; otherwise, you can probably use someone else's.

  • Do you need an exception TYPE that isn't represented by those in the Java platform?
  • Would it help users if they could differentiate your exceptions from those thrown by classes written by other vendors?
  • Does your code THROW more than one related exception?
  • f you use someone else's exceptions, will users have access to those exceptions? A similar question is, should your package be independent and self-contained?

According to Java Docs, you should write your own exception classes if you answer yes to any of the following questions; otherwise, you can probably use someone else's.



Discussion

No Comment Found