#1
  1. No Profile Picture
    Permanently Banned
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jul 2013
    Location
    Las Vegas
    Posts
    5
    Rep Power
    0

    Throw v/s Throws


    Hello Friends..
    How are you all...
    I am new to the java and learns core java right now...
    Any one please tell me the difference between the Throw and Throws..
    What is the basic difference between them and how it is used...
    please help..
    thank you in advance ..
  2. #2
  3. Java Junkie
    Devshed Specialist (4000 - 4499 posts)

    Join Date
    Jan 2004
    Location
    Mobile, Alabama
    Posts
    4,020
    Rep Power
    1285
    The keyword throw is used to actually cause an exception to occur. It must be used with an instance of a Throwable.

    e.g. throw new NullPointerException()

    The keyword throws precedes a list of exceptions that a method might throw. It is required for checked exceptions which have not been handed in the method, but you can also list unchecked exceptions.

    The unchecked exceptions are RuntimeException, Error, and their subclasses.

IMN logo majestic logo threadwatch logo seochat tools logo