raju a


{ City } bangalore
< Country > india
* Profession * software engineer
User No # 34370
Total Questions Posted # 0
Total Answers Posted # 2

Total Answers Posted for My Questions # 0
Total Views for My Questions # 0

Users Marked my Answers as Correct # 14
Users Marked my Answers as Wrong # 1
Questions / { raju a }
Questions Answers Category Views Company eMail




Answers / { raju a }

Question { Spenco, 80580 }

what is difference between throw and throws in exception?


Answer

throw : throw is used to throw user defined exceptions.
For ex: MyException written by user.it may be either
checked or unchecked exception.

throws: throws is used to throw exception those are handled by
JVM directly.
throws is used in method declaration to
intimate user that, it throw the exception that must
be handled by calling method.

Note :use throws when your method does not handle exception.

Is This Answer Correct ?    4 Yes 1 No

Question { Spenco, 80580 }

what is difference between throw and throws in exception?


Answer

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