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


Please Help Members By Posting Answers For Below Questions

explain different ways of using thread? : Java thread

1087


What are the differences between heap and stack memory in java?

1149


What is the difference between equals() and == in java?

1045


Write a program to find the whether a number is an Armstrong number or not?

1104


What is the difference between break and continue statements?

1131


What is an object in java and how is it created?

1145


What is parsing in java?

1046


Realized?

2268


Write a program to print count of empty strings in java 8?

1090


Is minecraft 1.15 out?

1048


How to sort array in descending order in java?

999


What is java string pool?

1087


What is a classloader in java?

1092


What is a constructor overloading in java?

1129


Explain public static void main(string args[]) in java.

1081