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
What is the public field modifier?
Can a top level class be private or protected?
What is the flag in java?
How to call one constructor from the other constructor ?
How can I right-justify a string?
What methods are used to get and set the text label displayed by a button object?
List the features of java programming language.
Explain about transient variables in java?
What is main method?
For ease of programming you can consider the maze as a 2D array with colors represented by below integer and characters (in capital letters). • B - Black • W -White • G- Green • R- Red R B W B W W W W W W B W B B W W W W W W W B W B W W W B W W W W B B W W W B W W W B W W B B B B W B W B W W B W W W B W W W B B B W W B W W W B W W B W B W W W B W B W W W W B B W W W W B W W W W W G Shortest Route Problem: • Solution that finds the shortest Route between Red and Green White will have 1 Weight. Red and Green carry no weights. Shortest path is the path with less weight when you add up the weights in the path.
What environment variables do I need to set on my machine in order to be able to run java programs?
Can a set contain duplicates?
What are the properties of thread?
can rmi and corba based applications interact ?
What are the differences between include directive and include action?