Saturday, May 19, 2018

Exception Handling Interview Questions and their uses

Leave a Comment

Exception Handling Interview Questions

What is the difference between ‘throw’ and ‘throws’ ?And it’s application?

Exceptions that are thrown by java run time systems can be handled by Try and catch blocks. With throw exception we can handle the exceptions thrown by the program itself. If a method is capable of causing an exception that it does not
handle, it must specify this behavior so the callers of the method can guard
against that exception.

What is the difference between ‘Exception’ and ‘error’ in java?

Exception and Error are the sub classes of the Throwable class. Exception class is used for exceptional conditions that user program should catch. With exception class we can subclass to create our own custom exception.
Error defines exceptions that are not excepted to be caught by you program. Example is Stack Overflow.

What is ‘Resource leak’?

Freeing up other resources that might have been allocated at the beginning of a method.

What is the ‘finally’ block?

Finally block will execute whether or not an exception is thrown. If an exception is thrown, the finally block will execute even if no catch statement match the exception. Any time a method is about to return to the caller from inside try/catch block, via an uncaught exception or an explicit return statement, the finally clause is also execute.

Can we have catch block with out try block? If so when?

No. Try/Catch or Try/finally form a unit.

What will happen to the Exception object after exception handling?

It will go for Garbage Collector. And frees the memory.

How many Exceptions we can define in ‘throws’ clause?

We can define multiple exceptions in throws clause.
Signature is.. : type method-name (parameter-list) throws exception-list

The finally block is executed when an exception is thrown, even if no catch matches it.


The subclass exception should precede the base class exception when used within the catch clause.


Exceptions can be caught or rethrown to a calling method.


The statements following the throw keyword in a program are not executed.


The toString ( ) method in the user-defined exception class is overridden.

If You Enjoyed This, Take 5 Seconds To Share It


Post a Comment