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

Search Java Interview Questions


 2137 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 'Exception handling' - 32 question(s) found - Order By Newest

 Q1. What things should be kept in mind while creating your own exceptions in Java?Core Java
Admin
info@buggybread.com
Ans. All exceptions must be a child of Throwable.

If you want to write a checked exception that is automatically enforced by the Handle or Declare Rule, you need to extend the Exception class.

You want to write a runtime exception, you need to extend the RuntimeException class.

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

   Like      Discuss      Correct / Improve     java   exceptions   exception handling   user defined exceptions   throwable   architecture   library development   technical architect   technical lead


Very Frequently asked.
 Q2. 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


 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. What is exception propogation ?Core Java
Anonymous
Ans. Passing the exception object to the calling method.

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

   Like      Discuss      Correct / Improve     java   exceptions   exception handling   throw


 Q5. 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


Frequently asked.
 Q6. When does the finally block gets executed ?Core Java2016-10-31 09:29:10

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 :   

   Like      Discuss      Correct / Improve     finally  exception handling  exceptions     Verilogue  Model N  CA Technologies  Mindteck      basic        frequent


Frequently asked at HCL Technologies ( Based on 3 feedback )
  Q7. Difference between Checked and Unchecked exceptions ?Core Java
Anonymous
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 :   

   Like      Discuss      Correct / Improve     java   exceptions   checked exceptions   unchecked exceptions   exception handling   basic interview question     Verilogue  F5 Network  Pegasystems  PegaSystems  SAP  Ciber  Conde Nast  Pramati Technologies  IBM  JP Morgan  HCL Technologies  Tata Consultancy (TCS)  Cognizant (CTS)  Cogent Infotech  MarketAxess  defense group  NETS INTERNATIONAL  Accenture  Integra Micro  ColdLight Solutions  Endeavor  Deloitte  Infosys      basic        frequent

Try 1 Question(s) Test


 Q8. 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


 Q9. Give an Example of checked and unchecked exception ?Core Java
Anonymous
Ans. ClassNotFoundException is checked exception whereas NoClassDefFoundError is a unchecked exception.

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

   Like      Discuss      Correct / Improve     java   exceptions   checked exceptions   unchecked exceptions   exception handling     SAP  JP Morgan



Do you think these are the Best Java Frameworks ?

OpenXavaSPRING MVCApache StripesCheck everything
that is Best in Java

Click Here



 Q10. 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


 Q11. Difference between throw and throws ?Core Java
Admin
info@buggybread.com
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 :   

   Like      Discuss      Correct / Improve     java   exceptions   exception handling   throw   throws   difference between   basic interview question      basic        frequent

Try 1 Question(s) Test


 Q12. How finally used under Exception Handling?Core Java
Admin
info@buggybread.com
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 :   

   Like      Discuss      Correct / Improve     java   exceptions   exception handling   try   finally   basic interview question     Oracle Engineering Group

Try 1 Question(s) Test


 Q13. 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


 Q14. what will be the output ?

class Animal {
public void eat() throws Exception {
}
}

class Dog2 extends Animal {
public void eat(){}
public static void main(){
Animal an = new Dog2();
an.eat();
}
}
Core Java
Admin
info@buggybread.com
Ans. Compile Time Error: Unhandled exception type Exception

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

   Like      Discuss      Correct / Improve     java   code   coding   overridding   late binding   exception handling   abstract class   abstract methods


 Q15. Can finally block throw an exception ?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   yes-no


 Q16. Tell me something about AssertionError ?Core Java
Admin
info@buggybread.com
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 :   

   Like      Discuss      Correct / Improve     java   error   exceptions   exception handling   assertion error   assertionerror


 Q17. What are the fail safe systems ?Operating System2016-06-09 09:29:43

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 :   

   Like      Discuss      Correct / Improve     fail safe systems   system design   exception handling     Verilogue


 Q18. 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?Core Java2016-10-18 11:37:51

Ans. Yes, with finally.

Yes, finally block will be executed even if there is no exception in try block.

If finally throws an exception, the exception gets thrown to the calling module.

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

   Like      Discuss      Correct / Improve     exception handling     Cognizant (CTS)      intermediate


 Q19. What happens to the Exception object after the exception handling is done ?Core Java2016-10-05 06:09:59

Ans. As with all other objects its garbage collected after its usage unless its rethrown.

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

   Like      Discuss      Correct / Improve     exceptions  exception handling        rare



Do you think these are the Best Java Frameworks ?

OpenXavaSPRING MVCApache StripesCheck everything
that is Best in Java

Click Here



 Q20. How can we catch an exception thrown by another thread ?Core Java2016-11-17 11:38:29

Ans. http://stackoverflow.com/a/6548203/2789764

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

   Like      Discuss      Correct / Improve     exception handling  exception      expert        rare


 Q21. Difference between Error and Exception ?Core Java2016-12-15 14:13:56

Ans. An Error indicates serious problems that a reasonable application should not try to catch whereas

An Exception indicates conditions that a reasonable application might want to catch.

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

   Like      Discuss      Correct / Improve     error  exception handling  exceptions     Accenture      basic        frequent


 Q22. 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


 Q23. When is the situation when finally section won't execute ?Core Java2017-01-09 12:56:46

Ans. If the process / app is abruptly killed or terminated.

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

   Like      Discuss      Correct / Improve     exception handling  finally     EPAM  Nix Solutions      intermediate

Try 1 Question(s) Test


  Q24. What is an exception and exception handling in Java ?Core Java2017-01-09 13:01:40

Ans. An Exception in java is the occurrence during computation that is anomalous and is not expected.

Exception handling is the mechanism which is used to handle such situations.


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

   Like      Discuss      Correct / Improve     exception handling     EPAM  Deloitte  Choice Hotels  Future Group  Cognizant (CTS)  Wipro  Infosys  HCL Technologies  Accenture  Amdocs  IBM  Ultramain Systems      basic        frequent


 Q25. What are the different ways to handle an exception ?Core Java2017-01-12 11:17:53

Ans. 1. Wrap the desired code in try block followed by a catch / finally to catch the exception

2. Declare the throws clause with exceptions that the code is expected to throw as an indication to the calling method to take care of it.

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

   Like      Discuss      Correct / Improve     exception handling     HCL Technologies  Wipro  Mindtree  HeadStrong

Try 1 Question(s) Test


 Q26. How should we handle errors while writing or accessing Stored Procedures?Database2017-01-19 13:55:55

Ans. Store Procedure returns the error code. Moreover we can put the call withing try block and catch SQL Exception.

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

   Like      Discuss      Correct / Improve     stored procedure  exception handling


 Q27. Can we have only try block in java ?Core Java2017-01-19 13:57:54

Ans. No, It should be followed by either catch or finally.

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

   Like      Discuss      Correct / Improve     try  exception handling


 Q28. What is Exception Wrapping ?2017-02-13 15:02:37

Ans. Exception wrapping is wrapping an exception object within another exception object and then throwing the outer exception.

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

   Like      Discuss      Correct / Improve     exception handling  exception wrapping  exceptions      intermediate        rare


 Q29. Can we catch errors in Java ? Core Java2017-05-23 08:21:10

Ans. Yes we can

try {
// code
} catch (Error ex) {
// handling code
}

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 :   

   Like      Discuss      Correct / Improve     exception handling  error handling  errors     ITech      intermediate


 Q30. In Case a method is declared to throw an exception , We can only use a call to that method if ...Core Java
a. We use the call within try block and catch the exception
b. We declare that the method is expected to throw the exception using throws
c. Both 1 and 2
d. Either 1 or 2

Ans.d. Either 1 or 2

 Q31. Which of the following is true ?Core Java
a. throw and throws are used to throw an exception
b. throw is used to throw an exception whereas throws is a declaration that the method can throw the exception
c. throws is used to throw an exception whereas throw is a declaration that the method can throw the exception
d. throw and throws are used to declare that an exception can be thrown by the method

Ans.b. throw is used to throw an exception whereas throws is a declaration that the method can throw the exception

 Q32. throws is a declaration that the ..... is expected to throw an exception ?Core Java
a. Variable
b. Method
c. Class
d. Interface

Ans.b. Method



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: