Golgappa.net | Golgappa.org | BagIndia.net | BodyIndia.Com | CabIndia.net | CarsBikes.net | CarsBikes.org | CashIndia.net | ConsumerIndia.net | CookingIndia.net | DataIndia.net | DealIndia.net | EmailIndia.net | FirstTablet.com | FirstTourist.com | ForsaleIndia.net | IndiaBody.Com | IndiaCab.net | IndiaCash.net | IndiaModel.net | KidForum.net | OfficeIndia.net | PaysIndia.com | RestaurantIndia.net | RestaurantsIndia.net | SaleForum.net | SellForum.net | SoldIndia.com | StarIndia.net | TomatoCab.com | TomatoCabs.com | TownIndia.com
Interested to Buy Any Domain ? << Click Here >> for more details...

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 spliterator in java8?

1007


Is void a data type in java?

923


What are the benefits of immutable objects?

948


What is the numeric promotion?

953


What is unicode datatype?

921


What is the purpose of the finalize() method?

1179


What is a generic data type?

965


What does you mean in math?

1013


What is finalize() function in java?

961


Can extern variables be initialized?

895


Why do we use threads in java?

1051


Objects or references which of them gets garbage collected?

917


Can a class with private constructor be extended?

879


Why is static used?

983


What is variable and its types?

970