what is difference between throw and throws in exception?

Answer Posted / siva y

Throw is used to explicitly raise a exception within the program, the statement would be throw new Exception(); throws clause is used to indicate the exceptions that are not handled by the method. It must specify this behavior so the callers of the method can guard against the exceptions.

Throws is specified in the method signature. If multiple exceptions are not handled, then they are separated by a comma. the statement would be as follows: public void doSomething() throws IOException,MyException{}

Is This Answer Correct ?    0 Yes 0 No



Post New Answer       View All Answers


Please Help Members By Posting Answers For Below Questions

What is difference between public static and void?

487


What is string substring?

563


What is the difference between Java Program Constructor and Java Program Method, What is the purpose of Java Program constructor Please Explain it Breafily?

600


What is a instance variable?

585


Can there be an abstract method without an abstract class?

541






Explain implementation and how is it different from conversion?

589


Does .length start 0 java?

569


Can a singleton class be inherited?

532


How many types of methods are there in java?

530


What are the elements of java?

567


How to find the index of the largest number in an arraylist java?

522


What is Java Reflection API? Why it’s so important to have?

608


What does the “static” keyword mean? Can you override private or static method in java?

636


What is difference between string and stringbuffer?

499


Which collection is ordered in java?

538