Java Exception Handling

Category Archives: Java Exception Handling

throws Keyword in Java

In java, throws the keyword is used to declare an exception. We know there are two types of exception checked and unchecked Exception. Checked exceptions(compile time) are those which force the programmer to handle it, without handle these exceptions the program doesn’t compile successfully. While unchecked exception(Runtime) doesn’t get checked during compilation.   “throws keyword” is mainly used for handling … Continue reading throws Keyword in Java

Exception Handling in Java

Exception Handling is the mechanism to handle Runtime Exceptions. We need to handle such exceptions to prevent abrupt termination of the program. It helps us to maintain the normal flow of the application.   What is Exception? An Exception can be anything which interrupts the normal flow of the program. When Exception occurs system generates an … Continue reading Exception Handling in Java

throw Keyword in Java

In java, throw keyword is used to throw an exception explicitly. Using “throw keyword” we can throw checked, unchecked  exceptions and user -defined exceptions. The throw keyword is mainly used to throw the custom exception. We will discuss these in tutorial User defined exceptions. The only object of the Throwable class or its sub-classes can … Continue reading throw Keyword in Java

Difference in Final, Finally and Finalize

The difference in final, finally and finalize is the imp from interview point of view. This is one of the most favorite question of many interviewers for Java freshers as well as for java experienced professionals. We will see the difference in all these. There are many differences between final, finally and finalize.   Difference in Final, Finally … Continue reading Difference in Final, Finally and Finalize

Finally Block in Java

Let’s learn about the Finally Block in Java. Finally, a keyword is related to Exception Handling in Java. In java finally block must be followed by the try or catch block and it always executes immediately after try-catch block exits.   The code inside the finally clause will always be executed, even if an exception is thrown … Continue reading Finally Block in Java

Multi catch Block in Java

A method can throw more than one exceptions. To handle these exceptions we need multiple catch blocks associated with the single try block.   A single try block can have multiple catch blocks. This is required when the try block has statements that generate different types of exceptions. If the first catch block contains the Exception class … Continue reading Multi catch Block in Java

Difference in throw and throws in Java

Let’s see What is Difference in throw and throws in Java. throw keyword and throws keyword both are related to Exception Handling in Java. The main difference between throw and throws is in their usage and functionality. where throws is used in method signature to declare Exception possibly thrown by any method, the throw is actually used to … Continue reading Difference in throw and throws in Java

Nested try catch Block in Java

Let’s see, What is nested try catch block in Java. The try-catch blocks can be nested. The try-catch block within the another try block body is known as nested try catch block.   Nested try-catch block Sometimes the situation may arise. some code part may cause more than one error. In such case, exception handler has to be … Continue reading Nested try catch Block in Java

User Defined Exception in Java

This tutorial will explain the User Defined Exception in Java. Java has good support for exception handling. Java also has a very good hierarchy in exception handling. Still, sometimes we need to create custom exceptions, i.e. Exceptions which are not defined in JDK or any third party library your application is using. User-defined exceptions in Java are also known as Custom … Continue reading User Defined Exception in Java

Exception Handling in Method Overriding

Let’s learn about Exception handling in Method overriding. There are few things to remember when overriding a method with exception handling. There are certain restrictions while overriding a method in case of exception handling in Java. Broadly there are two rules –   If the superclass method does not declare an exception If the superclass method does not declare … Continue reading Exception Handling in Method Overriding