Results 1 to 2 of 2

Thread: Can we use throw alone

  1. #1
    Junior Member
    Join Date
    Jul 2007
    Answers
    14

    Can we use throw alone

    Can we use throw method without using try in any place of code? and can anyone tell me what is the difference between throw and throws?


  2. #2
    Contributing Member
    Join Date
    Sep 2006
    Answers
    42

    Re: Can we use throw alone

    Hi,
    Yes. You can use throw alone without using try catch.

    EG:
    public void foo() throws Exception {
    throw new Exception();
    }

    Throw is used to throw an exception.
    Throws is used in a method declaration which says that this function throws an exception.

    Hope this helps.

    Regards,
    Sahil.


Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
About us
Applying for a job can be a stressful and frustrating experience, especially for someone who has never done it before. Considering that you are competing for the position with a at least a dozen other applicants, it is imperative that you thoroughly prepare for the job interview, in order to stand a good chance of getting hired. That's where GeekInterview can help.
Interact