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?

Answers were Sorted based on User's Feedback



what is difference between throw and throws in exception?..

Answer / neema

"throw" is used to handle user-defined exception.
JVM handles the exceptions which are specified by "throws"

Is This Answer Correct ?    261 Yes 50 No

what is difference between throw and throws in exception?..

Answer / pavithra

throws is used to throw an exception from the method
without handling that exception where as 'throw' is used
to throw the exception to catch block and handle it.

Is This Answer Correct ?    123 Yes 79 No

what is difference between throw and throws in exception?..

Answer / shiva

hi pavitra u r nswer is wrong

Is This Answer Correct ?    64 Yes 23 No

what is difference between throw and throws in exception?..

Answer / chandra sekhar

In Throws, what ever the exception you are declaring are
handle by JVM. If it is a user defined exception in throws
block, JVM doesn't know when to throw that exception. For
this purpose we use Throw for a certain conditions/logic to
throw these user defined exceptions.

I think the above makes sense.

Is This Answer Correct ?    45 Yes 5 No

what is difference between throw and throws in exception?..

Answer / anu mathew

throws:
Method capable of raising an exception but not handling the
same. i.e to say no Try Catch block is implemented in the
Method, to handle the exception.
The callers should create the Try Catch Block to safeguard
against the exception.
If the above is not followed it would result in Compilation
errors.

throw:
The method that raises the exception also handles the same
in its Catch block.
If unhandled the exception can also be handles by the
Callers Try Catch Block.
Hope this makes sense.

Is This Answer Correct ?    44 Yes 10 No

what is difference between throw and throws in exception?..

Answer / raj

throws --> throws declare that it throws the exception to
the calling method.

throw --> it is surrounded by the try catch block actually
it does the work, of throwing the exception.

For Example:

public void testMethod() throws BusinessException
{
try
{
}
catch(Exception exe)
{
// catch all the exceptions and provide some meaningful
message
throw BusinessException("An error occured while
trying to connect to DB");
}

}

Is This Answer Correct ?    43 Yes 13 No

what is difference between throw and throws in exception?..

Answer / srinath

throws keyword is used 2 delegate the responsibility of
exception handling 2 caller method where as throw keyword
used 2 hand over the creted customised excetion object 2
jvm 2 handle the excepion.

Is This Answer Correct ?    33 Yes 7 No

what is difference between throw and throws in exception?..

Answer / velayutham

throw- means user defined exception. we want throw manually
throw the exception.
throws- means jvm going to take all exception.

Is This Answer Correct ?    33 Yes 10 No

what is difference between throw and throws in exception?..

Answer / shiva

throw is used for to through exception system explicitly,and
throws is u sed for to throws exception means throws
ioexception and servletexception and etc.........

Is This Answer Correct ?    41 Yes 29 No

what is difference between throw and throws in exception?..

Answer / raju

throw : throw is used to throw exception by user whenever he
feels to throw exceptions. throw is used to throw
either user defined or runtime exception.
for ex : throw new MyException(), here MyException
is user written exception.
throw new NullPointerException(), here
NullPointerException is RuntimeException.

throws: throws is used by the method to throw exception to
the calling method. And method itself does not able
to handle it so it throws to calling method.

Is This Answer Correct ?    10 Yes 0 No

Post New Answer

More Core Java Interview Questions

What about features of local inner class?

0 Answers  


What environment variables do I need to set on my machine in order to be able to run java programs?

0 Answers  


What are java threads?

0 Answers  


Explain different ways of passing arguments to sub-routine?

1 Answers  


what is the difference between object and class

10 Answers   IBM,


How many java versions are there?

0 Answers  


What is finalize()? Is finalize() similar to a destructor?

0 Answers  


if the memory capacity is 700 presently occupied by process is 690. then another process request space(40) how this situation handled in java.

4 Answers   Wipro,


How many times garbage collector will invoke an object?s finalize() method?

4 Answers  


In real time project which driver did u use? What is the main functionality of the Prepared Statement?

3 Answers   Photon,


What do you mean by byte code?

0 Answers  


There are 2 methods in a class. Both have the same method signature except for return types. Is this overloading or overriding or what is it?

9 Answers   KPIT,


Categories