Thursday, May 30, 2013

Difference bw throw and thows



Difference between throws and throw:


Sr#
throw
throws
1.
It is a keyword that must be used as a part of method body only.
It is a keyword which is used as a part of method heading only.
2.
“throw” keyword is used for throwing User Defined Exception.
“throws” keyword gives an indication to the calling function to keep a call function under try and catch block.
3.
When we use “throw” keyword as a part of method body, it is mandatory for the Java Program to use “throws” keyword as a part of method heading.
When we use “throws” keyword as a part of method heading, it is optional to specify “throw” keyword.

No comments:

Post a Comment