Results 1 to 4 of 4
  1. #1
    bugger is offline Senior Member
    Join Date
    Nov 2007
    Posts
    111
    Rep Power
    0

    Default throwing Exception

    I want to throw exception manually. I tried the following but it fails.
    Java Code:
    throw java.lang.ArrayIndexOutOfBoundsException;
    I get following exception:
    Java Code:
    Exception in thread "main" java.lang.Error: Unresolved compilation problem: 
    	java.lang.ArrayIndexOutOfBoundsException cannot be resolved
    Please advice.

  2. #2
    ShoeNinja's Avatar
    ShoeNinja is offline Senior Member
    Join Date
    Oct 2007
    Posts
    124
    Rep Power
    0

    Default

    What does your method signature look like?

  3. #3
    bugger is offline Senior Member
    Join Date
    Nov 2007
    Posts
    111
    Rep Power
    0

    Default

    Java Code:
    public void calculateSum()
    {
    ...
    }
    Actually method has nothing to do with this. I want to know, can I raise an exception myself?

  4. #4
    ShoeNinja's Avatar
    ShoeNinja is offline Senior Member
    Join Date
    Oct 2007
    Posts
    124
    Rep Power
    0

    Default

    Yes. You just have to put 'throws whateverException' on the end of your signature.

    Java Code:
    public void calculateSum() throws InvalidSumException{
    
    }

Similar Threads

  1. Main method throwing specific Exception
    By bugger in forum New To Java
    Replies: 5
    Last Post: 05-13-2009, 02:34 PM
  2. exception
    By Oktam in forum New To Java
    Replies: 2
    Last Post: 03-23-2008, 07:01 PM
  3. Replies: 1
    Last Post: 03-08-2008, 06:41 PM
  4. Exception
    By Camden in forum New To Java
    Replies: 2
    Last Post: 11-26-2007, 11:50 PM
  5. Which statement is throwing a runtime error....
    By money123 in forum New To Java
    Replies: 1
    Last Post: 07-30-2007, 12:55 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
  •