Results 1 to 5 of 5
  1. #1
    brrrr is offline Member
    Join Date
    Mar 2012
    Location
    Malaysia
    Posts
    18
    Rep Power
    0

    Smile Problems calling a class with constructor throws Exception

    im trying to call a class containing constructor throws exception but I do not know how.

    example :

    1st class :

    ...
    .......

    public void actionPerformed (ActionEvent ae)
    {

    if(ae.getSource() == button1)
    {
    new EncryptPage(); //problem occured at this line
    }
    }

    ...........
    .....


    2nd class :

    public class EncryptPage
    {

    public EncryptPage() throws Exception
    {
    //code
    .......
    ...
    }
    }

    here is the error i get:

    error: unreported exception Exception; must be caught or declared to be thrown

    can anyone explain this to me?

  2. #2
    Norm's Avatar
    Norm is offline Moderator
    Join Date
    Jun 2008
    Location
    SW Missouri
    Posts
    17,306
    Rep Power
    25

    Default Re: Problems calling a class with constructor throws Exception

    unreported exception Exception; must be caught or declared to be thrown
    If you call a method or constructor that is defined that it can throw an exception, your code must do something to handle that exception if it is thrown.
    One way is to enclose the call to the method or constructor in a try/catch block.

    Another way is to pass responsibility for handling the exception to the caller of your method/constructor by defining your method to throw that exception.
    If you don't understand my response, don't ignore it, ask a question.

  3. #3
    DarrylBurke's Avatar
    DarrylBurke is offline Member
    Join Date
    Sep 2008
    Location
    Madgaon, Goa, India
    Posts
    11,188
    Rep Power
    19

    Default Re: Problems calling a class with constructor throws Exception

    Moved from Advanced Java. Please don't post beginner questions in that section.

    db
    If you're forever cleaning cobwebs, it's time to get rid of the spiders.

  4. #4
    DarrylBurke's Avatar
    DarrylBurke is offline Member
    Join Date
    Sep 2008
    Location
    Madgaon, Goa, India
    Posts
    11,188
    Rep Power
    19

    Default Re: Problems calling a class with constructor throws Exception

    You abandoned the last thread you started.
    Please help me in javax.mail to send a email..

    Not the best way to continue getting free help on a forum, that.

    db
    If you're forever cleaning cobwebs, it's time to get rid of the spiders.

  5. #5
    brrrr is offline Member
    Join Date
    Mar 2012
    Location
    Malaysia
    Posts
    18
    Rep Power
    0

    Default Re: Problems calling a class with constructor throws Exception

    I'm so sorry, my fault.

    thank you for your help

Similar Threads

  1. Calling method from a different class into a constructor
    By NewToJava_99 in forum New To Java
    Replies: 1
    Last Post: 11-27-2011, 11:00 PM
  2. Calling on class with throws IOException
    By gisler in forum Networking
    Replies: 5
    Last Post: 12-01-2009, 04:20 PM
  3. Replies: 11
    Last Post: 11-05-2009, 12:44 PM
  4. Replies: 0
    Last Post: 12-19-2007, 09:10 AM
  5. Replies: 0
    Last Post: 12-19-2007, 09:01 AM

Posting Permissions

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