Search Interview Questions | 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. |
|
| ||||
Interview Questions and Answers for 'Exception' - 82 question(s) found - Order By Rating | ||||
| ||||
Ans. Yes, We can pass the test even if the tested method throws an exception. One way is know as exception testing in which the tested method is expected to throw exception and hence the expectation is set accordingly. @Test(expected = IndexOutOfBoundsException.class) public void test(){} Other way is to just ignore if the tested code throws an exception. In that case , we can enclose the tested method call in the try block and within exception block, we just return gracefully. Exception testing is perfectly ok to be done as we would like test code in case an exception occurs and if the code is handling the exception properly. Ignoring the exception by putting the tested method call within try block isn't something normal and should be avoided. | ||||
Help us improve. Please let us know the company, where you were asked this question : | ||||
Like Discuss Correct / Improve  Junit exception testing | ||||
| ||||
Ans. Throwable in java is a class that is the superclass of all exceptions and errors which may occurs in java program.It extends obcect class. | ||||
Help us improve. Please let us know the company, where you were asked this question : | ||||
Like Discuss Correct / Improve  exception handling   throwable Asked in 1 Companies basic | ||||
| ||||
Ans. Returning from inside a finally block will cause exceptions to be lost. A return statement inside a finally block will cause any exception that might be thrown in the try block to be discarded. | ||||
Help us improve. Please let us know the company, where you were asked this question : | ||||
Like Discuss Correct / Improve  exception handling  finally block Asked in 1 Companies | ||||
| ||||
Ans. If we do not mention, Cloneable Interface to the Class which we want to Clone then we get this exception, only if we try to clone an object Like: public class TestClone{ @Override protected Object clone() throws CloneNotSupportedException { return super.clone(); } } In Main, You try to do: TestClone clone = new TestClone(); TestClone clone2 = (TestClone) clone.clone(); You will get CloneNotSupportedException. Just add -> public class TestClone implements Cloneable { and things are fixed. | ||||
Help us improve. Please let us know the company, where you were asked this question : | ||||
Like Discuss Correct / Improve  exceptions handling  cloning | ||||
| ||||
Ans. ExceptionHandler is Used to handle at Method level | ||||
Help us improve. Please let us know the company, where you were asked this question : | ||||
Like Discuss Correct / Improve  @ExceptionHandler | ||||
| ||||
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 : | ||||
Like Discuss Correct / Improve  exception handling  ClassNotFoundException  NoClassDefFoundError Asked in 1 Companies | ||||
| ||||
Ans. No. But It will throw ArrayStoreException at runtime. | ||||
Help us improve. Please let us know the company, where you were asked this question : | ||||
Like Discuss Correct / Improve  ArrayStoreException  arrays | ||||
| ||||
Ans. It's an exception that is thrown when we attempt to add value of an incompatible type to an array. For example - Object[] strArray = new String[2]; strArray[0] = 5; In this code, strArray reference of type Object has currently been assigned the String array but at line 2 we are trying to add an integer value. | ||||
Help us improve. Please let us know the company, where you were asked this question : | ||||
Like Discuss Correct / Improve  arrays   ArrayStoreException | ||||
| ||||
This question is still unanswered. Can you please provide an answer. | ||||
Help us improve. Please let us know the company, where you were asked this question : | ||||
Like Discuss Correct / Improve  exception handling | ||||
| ||||
Ans. The regular behavior of exception handling will occur. It will look for any immediate catch handler and if none is provided, it would be transmitted to the callers until a catch handler is found or it's out of main function. | ||||
Help us improve. Please let us know the company, where you were asked this question : | ||||
Like Discuss Correct / Improve  exceptions  finally | ||||
| ||||
This question is still unanswered. Can you please provide an answer. | ||||
Help us improve. Please let us know the company, where you were asked this question : | ||||
Like Discuss Correct / Improve  ArithmeticException | ||||
| ||||
Ans. never initialise local to null,yes it is bad pratice | ||||
Help us improve. Please let us know the company, where you were asked this question : | ||||
Like Discuss Correct / Improve  null  nullpointerexception | ||||
| ||||
Ans. Sometimes the calls move across layers of classes and functions and hence each layer needs to perform some function like cleaning if something goes wrong deep inside. | ||||
Help us improve. Please let us know the company, where you were asked this question : | ||||
Like Discuss Correct / Improve  exceptions  exceptions handling  rethrowing exception | ||||
| ||||
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 Asked in 1 Companies intermediate | ||||
| ||||
Ans. Optional is to be used for arguments / atrributes which are indeed optional i.e the request should continue even if they aren't provided. It should not be used for mandatory attributes or arguments as we would like application to shout out ( with error message / exception trace ) to signify a problem. | ||||
Help us improve. Please let us know the company, where you were asked this question : | ||||
Like Discuss Correct / Improve  optional  nullpointerexception  java8  java 8 Asked in 1 Companies | ||||
| ||||
Ans. It would result in endless function calls and hence eventually would result in stackoverflow exception. | ||||
Help us improve. Please let us know the company, where you were asked this question : | ||||
Like Discuss Correct / Improve  recursion  stackoverflowexception Basic   frequent | ||||
| ||||
Ans. This looks like the case for optimistic locking wherein hibernate suspects that the information in table was updated by some other transaction after the entity was loaded by current transaction. One way is to have synchronized entity state and don't detach the entity. Other could be to merge the entity with the table record rather than just directly persisting the entity. | ||||
Help us improve. Please let us know the company, where you were asked this question : | ||||
Like Discuss Correct / Improve  StaleObjectStateException  Optimistic locking | ||||
| ||||
Ans. The exception is thrown when a database constraint is violated. | ||||
Help us improve. Please let us know the company, where you were asked this question : | ||||
Like Discuss Correct / Improve  ConstraintViolationException | ||||
| ||||
Ans. Application is unable to insert a record as it violates a unique constraint. The exception states the constraint and Table can be located by the Entity mapping. So I will go to the DB and will first check to which all columns the unique constraint applies. And then I will go and check the code and logs to see how come the duplicate column values were attempted to be inserted when they were not supposed to be. | ||||
Help us improve. Please let us know the company, where you were asked this question : | ||||
Like Discuss Correct / Improve  ConstraintViolationException  SQLIntegrityConstraintViolationException | ||||
| ||||
Ans. We can declare the reference as final to avoid reassignment but again we can always initialize the final reference to null. Even if there was any such facility available , it would have meant poor use of resources by assigning a new object in memory to each reference that's created. Many a times references are just meant to refer to other objects which already have a reference i.e sharing object by multiple references. | ||||
Help us improve. Please let us know the company, where you were asked this question : | ||||
Like Discuss Correct / Improve  null  NullPointerException | ||||
| ||||
Ans. No. It's a resource and performance overhead. | ||||
Help us improve. Please let us know the company, where you were asked this question : | ||||
Like Discuss Correct / Improve  LazyInitializationException  Lazy Loading | ||||
| ||||
Ans. First resolution is a big No as it conveys no lazy loading in complete app. even second is advocating the same but for a particular mapping. third one is most appropriate if loading and dependent entity property access is closer to each other in code and can be accomplished. I don't mind using 4th too. | ||||
Help us improve. Please let us know the company, where you were asked this question : | ||||
Like Discuss Correct / Improve  lazy loading  lazy initialization  LazyInitializationException | ||||
| ||||
Ans. The error states that Hibernate is not able to initialize proxy / dependent entity objects as there is no session or transaction present. Very likely we are trying to load the dependent entities lazily but the call to dependent object property is not wrapped within the session or transaction. | ||||
Help us improve. Please let us know the company, where you were asked this question : | ||||
Like Discuss Correct / Improve  Lazy Loading  Lazy Initialization  org.hibernate.LazyInitializationException | ||||
| ||||
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 | ||||
| ||||
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 | ||||
| ||||
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 | ||||
| ||||
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 Asked in 4 Companies | ||||
Try 1 Question(s) Test | ||||
| ||||
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 Asked in 18 Companies basic   frequent | ||||
| ||||
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 Asked in 2 Companies intermediate | ||||
Try 1 Question(s) Test | ||||
| ||||
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 Asked in 1 Companies | ||||