Exception Handling
- 19 September
Java try with resources
In this post, we will see about Java try with resources Statement. Java try with resources is a feature of Java which was added into Java 7. It helps to close all the resources declared within try block. It automatically closes the resources after being used. A resource can be any file or a database […]
- 22 February
Java Exception Handling Interview Questions And Answers
Exceptional handling is one of the most important topics in core java. Here is list of questions that may be asked on Exceptional handling. Question 1: What is Exception ? Answer: Java doc says “ An exception is an event, which occurs during the execution of a program, that disrupts the normal flow of the program’s […]
- 15 February
Difference between throw and throws in java
In this tutorial, we are going to see difference between throw and throws in java. throw: throw keyword is used to throw any custom exception or predefine exception. For example: Let’s say you want to throw invalidAgeException when employee age is less than 18. Create a Employee class as below. [crayon-676797b7047b6489958993/] Create InvalidAgeException class as […]
- 19 October
Exception handling in java
Exceptions I have started writing about the and how to prepare for the various topics related to OCAJP exams in my blog. In my previous post, I have published few sample mock questions for StringBuilder class. In this post I am going to explain about the another OCAJP exam objective “Differentiate among checked exceptions, unchecked […]
- 17 July
How to create custom exception in java
In this post, we will see how to create custom exception in java. It is very simple to create custom exception in java. You just need to extends Exception class to create custom exception. Lets understand this with example. You have list of counties and if You have “USA” in list of country, then you […]
- 14 July
Difference between checked and unchecked exception in java
In this post, we will see difference between checked and unchecked exception in java. It is important question regarding exceptional handling. What is Exception? Exception is unwanted situation or condition while execution of the program. If you do not handle exception correctly, it may cause program to terminate abnormally. What is checked exception? Checked exceptions […]
- 19 June
Can We Have Try without Catch Block in Java
In Java, it’s possible to use a try block without a catch block, but it must be followed either by a finally block or be part of a try-with-resources statement. Let’s see both cases with the help of examples: 1. try-finally Structure You can use a try block with a finally block. As you may […]