The "what's wrong" questions had reminded me a funny error that you could make if you want to "raise" an exception but you forget the keyword "throw".Īt the beginning of the article there is a code that has a problem. Most common example of using throw in place of return is throwing UnSupportedOperationException from an empty method as shown below : Throwable or any class derived from Throwable), throw keyword transfers control of execution to the caller so it can be used in place of return keyword. Syntactically you can throw any Throwable (i.e. On the other hand, throw keyword is actually used to throw any Exception. This signifies a lot of things like method is not going to handle Exception instead it's throwing it, if method throws checked Exception then the caller should provide compile-time exception handling etc. throws keyword is used in method signature to declare which checked exception method can throw, you can also declare unchecked exception, but that is not mandatory by the compiler. Though they are similar in terms that both are used in Exception handling, they are different on how and where they are used in code. throw and throws keyword may look quite similar, especially if you are new to Java programming and haven't seen much of it. One more Java Exception interview questions from beginners kitty. In this article we will see some Java Error and Exception interview questions asked to fresher, experienced and senior Java developers in Java J2EE interviews. If programmer is familiar with infamous and dodgy ClassNotFoundException or OutOfMemoryError, there is a good chance that he has some good practical experience under his belt. Some Interviewer also test debugging skill of programmers, as resolving Exceptions quickly is another trait of solid Java programming knowledge. Though multithreading, garbage collection, JVM concepts and questions from object oriented design rules these interviews, you should always expect and prepare some questions on effective error handling. Questions from Error and Exception in Java mostly based on the concept of Exception and Error in Java, How to handle Exception, best practices to follow during Exception handling etc. Exception handling is an important aspect of Java application development and its key to writing robust, stable Java programs, which makes it natural favorites on interviews. You will always see some interview questions from Exception and Error handling in core Java Interviews.