Results 1 to 3 of 3
  1. #1
    f22raptor is offline Member
    Join Date
    Aug 2011
    Posts
    16
    Rep Power
    0

    Default Throws and Throw

    Hi all,

    The topic of exception handling is really baffling me. First of all i would like to know that how will i need to know that my method needs to throw an exception? Secondly what is the difference between throws and throw?

    If i may...is throw used when i dont want to use try/catch statement?? and also the exception thrown by my method is my defined by myself?? in other words when the exception is user defined?? correct if am wrong.


    Thank u.

  2. #2
    f22raptor is offline Member
    Join Date
    Aug 2011
    Posts
    16
    Rep Power
    0

    Default

    sorry by that i meant to say that do we also use throw because we dont want to create the own exception class. this statement of mine "If i may...is throw used when i dont want to use try/catch statement?" is wrong kindly ignore that.

  3. #3
    JosAH's Avatar
    JosAH is offline Moderator
    Join Date
    Sep 2008
    Location
    Voorschoten, the Netherlands
    Posts
    13,773
    Blog Entries
    7
    Rep Power
    21

    Default

    The keyword 'throws' is used in the method header to mention the checked exceptions that can be thrown by this method; there is no need to mention the unchecked exceptions. The 'throw' keyword is used to throw any object that is or extends from the Throwable class.

    kind regards,

    Jos
    cenosillicaphobia: the fear for an empty beer glass

Similar Threads

  1. Throw and catches
    By cdawg_2010 in forum New To Java
    Replies: 3
    Last Post: 11-23-2010, 02:36 PM
  2. where to use throw and throws
    By javastuden in forum New To Java
    Replies: 4
    Last Post: 11-02-2010, 04:31 PM
  3. About throw message
    By killerf2006 in forum New To Java
    Replies: 4
    Last Post: 08-22-2010, 12:48 PM
  4. throw exception
    By GIRISH PATEL in forum New To Java
    Replies: 4
    Last Post: 04-23-2009, 05:35 AM
  5. Difference between Throws and Throw
    By Poonam in forum New To Java
    Replies: 7
    Last Post: 02-06-2008, 05:52 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •