Java - Interview Questions and Answers for 'Catch' | Search Java Interview Question - javasearch.buggybread.com
Javasearch.buggybread.com
Share

Search Java Interview Questions


 2098 questions in repository.
 There are more than 200 unanswered questions.
Click here and help us by providing the answer.
Label / Company      Label / Company / Text

   



Interview Questions and Answers for 'Catch' - 9 question(s) found - Order By Newest

Very Frequently asked.
 Q1. Explain throw, throws , try and catch in Java ?Core Java
Admin
info@buggybread.com
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 :   

   Like      Discuss      Correct / Improve     java   exception handling   throw   throws   try   catch     Vidram Solutions  Cognizant (CTS)      basic        frequent


 Q2. How can we make sure that a code segment gets executed even in case of uncatched exceptions ?
Anonymous
Ans. By putting it within finally.

 Help us improve. Please let us know the company, where you were asked this question :   

   Like      Discuss      Correct / Improve     java   oops   exceptions   finally   uncatched exceptions      basic        frequent


 Q3. Is it necessary that each try block to be followed by catch block ? Core Java
Anonymous
Ans. It should be followed by either catch or finally block.

  Sample Code for Retry in case of exception

 Help us improve. Please let us know the company, where you were asked this question :   

   Like      Discuss      Correct / Improve     java   exceptions   exception handling   try   catch   finally  Oracle OCA Test     Accenture  Cognizant (CTS)      basic        frequent

Try 1 Question(s) Test


 Q4. Can we have try and catch blocks within finally ?Core Java
Admin
info@buggybread.com
Ans. Yes

 Help us improve. Please let us know the company, where you were asked this question :   

   Like      Discuss      Correct / Improve     java   exceptions   exception handling   finally   try   catch   yesno


 Q5. How does a try statement determine which catch clause should be used to handle an exception?Core Java
Anonymous
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 :   

   Like      Discuss      Correct / Improve     java   exceptions   exception handling   try   catch      basic        frequent


 Q6. Can finally block be used without catch ?Core Java
Anonymous
Ans. Yes but should follow "try" block then.

 Help us improve. Please let us know the company, where you were asked this question :   

   Like      Discuss      Correct / Improve     java   exceptions   exception handling   try   catch   finally   yes-no

Try 1 Question(s) Test


 Q7. Will finally be called always if all code has been kept in try block ?Core Java
Admin
info@buggybread.com
Ans. 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 :   

   Like      Discuss      Correct / Improve     java   exceptions   exception handling   try   catch   finally   system   system.exit


 Q8. Which of the following is not possible ?

a. try block followed by catch
b. try block followed by finally
c. try block followed by catch block and then finally
d. try block without catch or finally block
Anonymous
Ans. try block without catch or finally block

 Help us improve. Please let us know the company, where you were asked this question :   

   Like      Discuss      Correct / Improve     exceptions   java   try-catch   finally

Try 1 Question(s) Test


 Q9. What is the difference between following code segments

1.

try {
for(int i=0;i<100;i++){
calculate(i);
}
} catch (Exception ex) {
System.out.println("Error while processing")
}

and

2.

for(int i=0;i<100;i++){
try {
calculate(i);
} catch (Exception ex) {
System.out.println("Error while processing")
}
}
Core Java2016-12-29 15:42:10

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 :   

   Like      Discuss      Correct / Improve     exception handling  try catch     Tieto




Subscribe to Java News and Posts. Get latest updates and posts on Java from Buggybread.com
Enter your email address:
Delivered by FeedBurner



comments powered by Disqus
 

Help us and Others Improve. Please let us know the questions asked in any of your previous interview.

Any input from you will be highly appreciated and It will unlock the application for 10 more requests.

Company Name:
Questions Asked:
         

X Close this

X Close this

Help Us Improve.
Please share your
interview experience.

Company Name:   


Questions Asked: