adspace
What is the difference between throw and throws?
Answer Posted / rakesh nath
Throw clause is used in any part of the code where you want
to throw any specific exception to the calling method while
throws can be termed as a substitute for try-catch block.
When an exception occurs in a program, the compiler needs to
know what should be done with that exception. For that
either we should have a try-catch block or the method should
have the throws clause attached, as follows.
<access-modifier> <return-type> myMethod(<parameter-list>)
throws <exception-list>
for example, public void meth1() throws MyException
throw can handle only ONE throwable object while throws can
handle multiple throwable objects seperated by commas.
| Is This Answer Correct ? | 13 Yes | 1 No |
Post New Answer View All Answers
explain different ways of using thread? : Java thread
What are the differences between heap and stack memory in java?
What is the difference between equals() and == in java?
Write a program to find the whether a number is an Armstrong number or not?
What is the difference between break and continue statements?
What is an object in java and how is it created?
What is parsing in java?
Realized?
Write a program to print count of empty strings in java 8?
Is minecraft 1.15 out?
How to sort array in descending order in java?
What is java string pool?
What is a classloader in java?
What is a constructor overloading in java?
Explain public static void main(string args[]) in java.