Interview Questions on Exception Handling in Java

How have you handled exceptions in the projects that you have worked on?

You can check the below link to learn about the basic exception handling in Java.

http://www.jcombat.com/core-java/exception-handling-in-java


Have you used custom exceptions?

http://www.jcombat.com/core-java/user-defined-or-custom-exceptions

Why do we need custom exceptions?

http://www.jcombat.com/core-java/user-defined-or-custom-exceptions

How many types of exceptions are there?

http://www.jcombat.com/core-java/exception-handling-in-java

Could you provide examples of checked and unchecked exceptions?

IOException is a checked exception while ArithmeticException is an unchecked exception.

Tell the output of the following:

Output:

Exception in thread “main” CustomException: Inside Finally block
at TestMain.main(TestMain.java:9) 

What we notice here, is that the CustomException which is thrown inside catch block disappears. So let’s note this point that, only the last exception that is thrown inside try-catch-finally blocks, propagates up the call stack.

Is NullPointerException a checked exception?

No. It is an unchecked exception.

Receive our updates to your inbox

Get more stuff like this
in your inbox

Subscribe to our mailing list and get interesting stuff and updates to your email inbox.