Java-Throwable Class and Generic Exception Catch

Throwable Class All the exceptions are derived from the class Throwable. Thus, Throwable is a superclass of all other exception class. There are two subclasses of Throwable class. They are Exception and Error. The Exception class has a many subclasses, such as RunTimeException, IOException and etc….   Generic Exception catch A catch statement that uses a superclass will … Read more…

Java-Displaying Exception Description

Displaying Exception Description You can display the description about the exception in a println( ) statement by simply passing the exception as an argument. Program Program Source class Javaapp { public static void main(String[] args) { try{ int a=1/0; }catch(ArithmeticException ex) { System.out.println(“Exception : “+ex); } System.out.println(“Execution Complete”); } }

Java-Common Exception and Multiple Catch Blocks

Common Exception Exception Type Cause of Exception ArithmeticException Math errors such as divison by zero ArrayIndexOutOfBoundsException Bad array indexes ArrayStoreException When a program tries to store the wrong type of data in an array FileNotFoundException An attempt to access a nonexistent file IOException General input, output failures NullPointerException Referencing a null object NumberFormatException A conversion … Read more…