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
What is difference between public static and void?
What is string substring?
What is the difference between Java Program Constructor and Java Program Method, What is the purpose of Java Program constructor Please Explain it Breafily?
What is a instance variable?
Can there be an abstract method without an abstract class?
Explain implementation and how is it different from conversion?
Does .length start 0 java?
Can a singleton class be inherited?
How many types of methods are there in java?
What are the elements of java?
How to find the index of the largest number in an arraylist java?
What is Java Reflection API? Why it’s so important to have?
What does the “static” keyword mean? Can you override private or static method in java?
What is difference between string and stringbuffer?
Which collection is ordered in java?