Top 40+ Java Exception Handling Interview Questions and Answers - 1
What is difference between throw and throws keyword in Java?
throws keyword is used with method signature to declare the exceptions that the method might throw whereas throw keyword is used to disrupts the flow of program and handing over the exception object to runtime to handle it.
When is finally block NOT called?
Finally block is NOT called in following cases: if the JVM exists while the try or catch code is being executed. This may happen due to System.exit() call.
If the thread executing the try or catch code gets interrupted or killed. In this case, the finally block may not execute although the application keeps working.
If an expression is thrown in finally block is not handled. In this case, the remaining code is finally block may not execute.
What is the Array Store Exception thrown?
When copying elements between different arrays, if the sources or destination arguments are not arrays or their types are not compatible, an Array Store Exception will be thrown.
What situations are best suitable for implementing assertions?
Assertions can best be implemented.
As Internal Invariants
As Control flow Invariants
As Pre conditions and Post conditions
As Class Invariants
Can we have an empty catch block?
We can have an empty catch block but it’s the example of worst programming.
We should never have empty catch block because if the exception is caught by that block, we will have no information about the exception and it will be a nightmare to debug it.
There should be at least a logging statement to log the exception details in console or log files.
1000+ IQ Puzzles Questions and Answers More
1000+ IBPS Puzzles Questions and Answers More
Classes and Objects in C++ Programming Questions and Answers More
100+ MCQ on Constructor and Destructor in C++ More
1000+ Simple Puzzles for Interview with Answer More
100+ Computer Science Quiz Questions with Answers Pdf More
Java Interview Questions and Answers for Experienced Pdf More
Java Applet Interview Questions and Answers Pdf More
PG TRB Commerce Exam Date 2020-2021, Age Limit, Jobs Notifications More
Analogy Questions and Answers for SSC CGK, CHSL, MTS, JE, SI Exams More