Java has very good support of handling Error and Exception, It has a well-defined Exception hierarchy and language level support to throw and catch Exception and deal with them. Java Programmers often deals with built-in exceptions from
java.lang package and several others which are already defined in JDK API e.g.
NullPointerException. If you have read Effective Java, you may remember advice of Joshua Bloch regrading Exception. According to him you should try to reuse the Exception classes provided in the JDK, e.g.,
IndexOutOfBoundException,
ArithmeticException,
IOException, and
java.lang.ArrayIndexOutOfBoundsException , instead of creating new ones for similar purpose. But there are cases when a user defined, custom exception provides better opportunity to deal with special cases. So remember, you can always create you own Exception classes by extending from the class Exception or one of its sub classes. Also note that RuntimeException and its sub classes are not checked by the compiler and need not be declared in the method's signature. Therefore, use them with care, as you will not be informed and may not be aware of the exceptions that may occur by using that method (and therefore do not have the proper exception handling codes) – a bad software engineering practice. Once again, even Joshua Bloch has advised to use standard exception in Effective Java.