by Dinesh Thakur Category: Exception Handling

Typically, code in a try-block can throw more than one kind of exception. If this is the case then you can put several catch blocks after the try block to handle them, one for each possible exception. When an exception is generated, the JVM searches the catch blocks in order. The first catch block with a parameter that matches the exception thrown will execute, any remaining catch blocks will be skipped.

 
by Dinesh Thakur Category: Exception Handling

You can also throw an exception explicitly. This is accomplished using the throw statement. A throw statement is executed to indicate that an exception has occurred. The exception that you throw using the throw statement can either be the standard system exception or the one that are created by you. The syntax of throw statement is as follows,

 
by Dinesh Thakur Category: Exception Handling

Based on the severity of the error, Exception classes are categorized into two groups: unchecked exceptions and checked exceptions. Unchecked exceptions are those that can be either handled or ignored. If the programmer ignores an unchecked exception, the program will terminate when such an error occurs. On the other hand, if a handler is provided for an unchecked exception, the result of the occurrence of such an error will depend on the code written in the exception handler. An example of an unchecked exception is the class RuntimeException (and its sub-classes), which is a sub-class of the class Exception. It is a very important class in Java programming.

 
by Dinesh Thakur Category: Exception Handling

Java.lang.Exception Class is the superclass for all exceptions in Java. To creating our own extensions, we simply extend this class.

 
by Dinesh Thakur Category: Exception Handling

An exception handler designed to handle a specific type of object may be preempted by another handler whose exception type is a super-class of that exception object. This happens if the exception handler for that exception type appears earlier in the list of exception handlers. That is, while using multiple catch statements, it is important to be aware of the order of exception classes and arrange them correctly.

 

Page 2 of 2



About Dinesh Thakur

Dinesh ThakurDinesh Thakur holds an B.SC (Computer Science), MCSE, MCDBA, CCNA, CCNP, A+, SCJP certifications. Dinesh authors the hugely popular blog. Where he writes how-to guides around Computer fundamental , computer software, Computer programming, and web apps. For any type of query or something that you think is missing, please feel free to Contact us.