© 2014 Firstsoft Technologies (P) Limited. login
Hi 'Guest'
Home SiteMap Contact Us Disclaimer
enggedu

Home Placements Interview Questions Java Interview Questions And Answers Java Interview Questions On Flow Control and Exception Handling ▼

Java Interview Questions On Flow Control and Exception Handling

10. Can we Catching Multiple Exceptions in java?

Answer:

Yes, we can catching multiple exceptions.
To catch multiple exceptions define multiple BI blocks for each exception class, or define a single catch block with super class of all exception classes. If you define a catch block by passing super class of  exception classes then all the subclasses of that exception can be handled. If you specify one exception class in one catch block and a parent class of that exception in another catch block then you can handle more specific exceptions.

11. How we through the exception using throw statement?

Answer

To throw exceptions you need to do two things, first create the an instance of the class which is subclass of java.lang.Thowable class, then use the throw keyword to throw the exception. Normally this is combined in a single statement.
throw new IOException("File not found exception");

12. Explain About throws statement?

Answer

In Java a method can throw an exception if it encounters a situation that it cannot be handled. Forexample the code that attempts to read from a file, that file may not exists or it may be empty, then you need to declare the method as fallows,

public String readLine() throws IOException {
// code that might generate exceptions
}

13. What are Different types of exception in java?

Answer

Types of exceptions:

  • l Checked Exceptions
  • l Runtime Exceptions
  • l Errors

The checked exceptions describes that the problems can arise in a correct program, such as user mistakes, I/O problems.
Runtime exceptions are program bugs examples array out of bounds, these need to be corrected and fixed.
The errors are unusual exceptions, these kind of exceptions we do not have to handle them. For example computer running out of memory situations.

Previous Next
1 2 3 4 5 6 7 8 9
SLogix Student Projects
bottom