What is the difference throw and throws

Showing Answers 1 - 10 of 10 Answers

rabbi

  • Jul 2nd, 2006
 

Both throw and throws are keywords in Java
. throw
Causes the declared exception instance to be thrown. This causes execution to continue with the first enclosing exception handler declared by the catch keyword to handle an assignment compatible exception type. If no such exception handler is found in the current method, then the method returns and the process is repeated in the calling method. If no exception handler is found in any method call on the stack, then the exception is passed to the thread's uncaught exception handler.
throws
Used in method declarations to specify which exceptions are not handled within the method but rather passed to the next higher level of the program. All uncaught exceptions in a method that are not instances of RuntimeException must be declared using the throws keyword.

  Was this answer useful?  Yes

Sumeeth R Tewar

  • Jul 12th, 2006
 

Both throw and throws are keywords.

throw is used to explicitly throw a user defined or predefined exception.

throws is used when dont want to handle the exception and just specify that what all exceptions the method might throw.

syntax :

access returntype  methodName() throws Exception list

note : only checked exceptions can be put up on the exception list.

  Was this answer useful?  Yes

siva kumar reddy

  • Aug 9th, 2006
 

hi,

throws exception is used to throws the exception does not handle it.

throw clause is used to create the exception.and handle it forcebily.

these two statements are quite opposite

cheers

siva

  Was this answer useful?  Yes

priyaranjan

  • Oct 3rd, 2007
 

Thow is a excption
Throws is a error

  Was this answer useful?  Yes

sampra

  • Feb 14th, 2008
 

throw when toy have to send exception or userdefine exception by your own.
throws is use to throw method level exception

  Was this answer useful?  Yes

Give your answer:

If you think the above answer is not correct, Please select a reason and add your answer below.

 

Related Answered Questions

 

Related Open Questions