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
Why java does not support pointers?
Can we overload run() method in java?
What is java reflection?
What is static synchronization?
How can you write a loop indefinitely in java programming?
how to create multithreaded program? : Java thread
How does linkedlist work in java?
What does method mean?
how many types of Inheritance?
Can I overload to string method
Why is java not 100% pure oops?
How many types of memory areas are allocated by JVM in java?
What is the difference between static class and normal class?
Is java type safe?
What is an escape character in java?