DIFFERENCE BETWEEN THROW AND THROWS KEYWORD IN JAVA

Royce Roy

Total Post:149

Points:1043
Posted by  Royce Roy
Java 
 918  View(s)
Ratings:
Rate this:
what is difference between throw and throws keyword in Java
  1. Mayank Tripathi

    Post:397

    Points:3117
    Re: Difference between throw and throws keyword in Java

    throw
    1)throw is used to explicitly throw an exception.
    2)checked exceptions can not be propagated with throw only.
    3)throw is followed by an instance.
    4)throw is used within the method.
    5)You cannot throw multiple exception


    throws
    1)throws is used to declare an exception.
    2)checked exception can be propagated with throws.
    3)throws is followed by class.
    4)throws is used with the method signature.
    5)You can declare multiple exception e.g. public void method()throws IOException,SQLException.

Answer

NEWSLETTER

Enter your email address here always to be updated. We promise not to spam!