0

A practical and simple example will be very helpful.When already try-catch block and throws keyword available ,is it worthy throwing an exception object manually? try-catch block helps in catching an exception and displaying the information about that exception during Runtime right? Can also anyone could tell the difference between "throw" and "throws" keyword?

Hema Chandra
  • 363
  • 2
  • 4
  • 16

1 Answers1

0

The meaning is there in the words only.

Keyword throw is a action word, for example throw new Exception() means the code is throwing an Exception, meaning if the execution control reaches this code, exception will be thrown. This is internal to a method.

Keyword throws is a declaration to the users of the method (code calling the method) that the method can throw an exception.

try-catch is an mechanism to try a code which can throw an exception and then catch the same if thrown.

nits.kk
  • 5,204
  • 4
  • 33
  • 55