What is the difference between throw and throws ?

What is the difference between throw and throws ?

Throw is used to propagate an exception to its caller inorder to let the calling method to handle an exception rather than implementation method.Throw keyword is always used at block level but not at method signature level.
All built-in exceptions are automatically thrown by the JVM. But, built-in exceptions can be programmatically thrown by the developer using throw keyword.
All user defined exceptions must be programmatically thrown using �throw� keyword.
throw ;
throw new ArithmeticException(�/ by zero�);
Throws keyword is used at method signature level to specify the type of exception a method throws.
  � <,ExceptionTypeⁿ>{


By:Sumit Tripathi
Date:2021-05-15 00:00:00

Post Your Answers

User Email:

User Name:

Related Java Subjective Links

Java Subjective interview questions and answers for experienced and fresher