Java-Exception Types and Throws Statement

Exception Types Java exceptions are divided into two categories, called checked and unchecked exceptions. All subclasses of RuntimeException class are unchecked exceptions. All other exceptions are checked exceptions.   Checked Exception For checked exceptions, the compiler checks if your program handles them, either by catching them or by specifying (with a throws clause) that the … Read more…

Java-User Defined Exception

User Defined Exception You can create your own exception by extending Exception class. The throw keyword are used while implementing user defined exceptions. Following program demonstrates the use of a user-defined subclass of Throwable class. Note that Exception is a subclass of Throwable and therefore MyOwnException is a subclass of Throwable class. An object of … Read more…

Java-Throw Statement

Throw Statement So far, you have only been catching exceptions that are thrown by the Java run-time system. However, it is possible for your program to throw an exception explicitly, using the throw statement. The general form of throw is shown here: throw exceptionObject; Here, exceptionObject must be an object of type Throwable(Throwable is a … Read more…

Java-Finally Statement

Finally Statement Java supports another statement knows as finally statement. The JVM ensures that the statements placed in the finally block are executed whether or not an exception occurs. So, even if no exception occurs during the execution of a try block, the finally block is executed. When an exception occurs, an appropriate catch block … Read more…

Java-Ignore Exception

Ignore Exception Java does not require any processing of the exception at all. We can simply have a catch statement with an empty block to avoid program termination. Example : catch(Exception ex); The catch statement simply ends with a semicolon, which does nothing. This statement will catch an exception and then ignore it. Program Source … Read more…

Java-Common Error in Generic Exception Catch

Common Error in Generic Exception Catch When you use multiple catch statements, it is important to remember that exception subclasses must come before any of their superclasses. This is because a catch statement that uses a superclass will catch exceptions of that type plus any of its subclasses. Thus, a subclass would never be reached … Read more…