More than 3000 questions in repository. There are more than 900 unanswered questions. Click here and help us by providing the answer. Have a video suggestion. Click Correct / Improve and please let us know.
Ans. Checked exceptions are the exceptions for which compiler throws an errors if they are not checked whereas unchecked exceptions are caught during run time only and hence can't be checked.
Help us improve. Please let us know the company, where you were asked this question :
Ans. throw is used to re throw an exception.throws is used to declare that the method throws the respective exceptions.try block is used to identify if the respective block has thrown any exception.catch is used to catch the exception that has been thrown by the respective try block.
Help us improve. Please let us know the company, where you were asked this question :
Ans. ClassNotFoundException is an exception that occurs when we try to load a class at run time using Class.forName() or loadClass() methods and mentioned classes are not found in the classpath.
NoClassDefFoundError is an error that occurs when a particular class is present at compile time, but was missing at run time.
Help us improve. Please let us know the company, where you were asked this question :
Ans. A finally block of code always executes, whether or not an exception has occurred.The only time finally won't be called is if you call System.exit() or if the JVM crashes first.
Help us improve. Please let us know the company, where you were asked this question :
Ans. When an exception is thrown within the body of a try statement, the catch clauses of the try statement are examined in the order in which they appear. The first catch clause that is capable of handling the exception is executed. The remaining catch clauses are ignored.
Help us improve. Please let us know the company, where you were asked this question :
Ans. throw is used to explicitly throw an exception especially custom exceptions, whereas throws is used to declare that the method can throw an exception.
We cannot throw multiple exceptions using throw statement but we can declare that a method can throw multiple exceptions using throws and comma separator.
Help us improve. Please let us know the company, where you were asked this question :
Ans. The finally keyword is used to create a block of code that follows a try block. A finally block of code always executes, whether or not an exception has occurred.
Help us improve. Please let us know the company, where you were asked this question :
Ans. Yes. Methods invoked from within a finally block can throw an exception. Failure to catch and handle such exceptions results in the abrupt termination of the entire try block.
Help us improve. Please let us know the company, where you were asked this question :
Ans. AssertionError is actually a fatal fault or a bug in the program. We may not like to continue program , request or thread execution if this error occurs as this condition is the assumption to continue further execution.
Help us improve. Please let us know the company, where you were asked this question :
Ans. Fail Safe systems are tolerant systems that continue processing even if they sense any problem. the objective here is to continue with the processing even if there are some problems instead of completely shutting it down. Example could be to catch an exception and still letting it complete with partial results.
Help us improve. Please let us know the company, where you were asked this question :
Q20. Can we have try statement without catch? If try statement contains return will the finally block be executed? What happens if there is an exception inside finally block?
Ans. In first case the whole loop will terminate as soon as any exception happens in the method calculate ( assuming calculate method is not handling its exception and those are thrown back at the calling method )
In Second case exception will be caught for individual iteration and hence it wont break the loop and will continue for the next iteration.
Help us improve. Please let us know the company, where you were asked this question :
but we shouldn't ideally do that as errors are mostly JVM based and not application based and there is rarely we can do something about it. Very likely catching and not re throwing would lead to muting their response or trace.
Help us improve. Please let us know the company, where you were asked this question :