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 difference between throw and throws in exception?

Answer Posted / chaitanya

throw:the throw keyword is used to throw the exception manually,that is when you feel a particular line in your code, when executed is capable of having some exception then you use throw keyword as:

throw new MyException(arguments if any);
this leads to instantiating of the MyException class and exception is thrown


throws: this is to be used when you are not using the try catch statement in your code but you know that this particular class is capable of throwing so and so exception(only checked exceptions).in this you do not use try catch block but write using the throw clause at appropriate point in you code and the exception is thrown to caller of the method and is handeled by it. eg:

void trouble()throws IOException,any other exceptions just separate them with commas.......
{
/* throw statement at appropriate step,
no need to use try catch here,exception would be thrown to caller and u should provide try catch block to handle exception there else this process cotinues further till
appropriately it is handeled or prog terminates abruptly */
}

Is This Answer Correct ?    0 Yes 0 No



Post New Answer       View All Answers


Please Help Members By Posting Answers For Below Questions

Explain parallel processing in java8?

1255


How is it possible for two string objects with identical values not to be equal under the == operator?

996


What is the latest version of java?

1135


what is the use of bean managed and container managed with example?

1977


What is jit and its use?

991


How do you sort an array in java?

996


Explain notifyall() method of object class ?

1090


Give differences between Quicksort &Mergesort. When should these sorts be used andwhat is their running time in java?

1243


Difference between doublesummarystatistics, intsummarystatistics and longsummarystatistics ?

988


What is difference between final and immutable?

1150


Explain jvm, jre, and jdk?

1017


What is use of map in java?

1013


What methods are used to get and set the text label displayed by a button object?

1017


What is constant in programming?

1112


What are the advantages of passing this into a method instead of the current class object itself?

1674