Results 1 to 5 of 5
- 04-20-2012, 01:41 AM #1
Member
- Join Date
- Mar 2012
- Location
- Malaysia
- Posts
- 18
- Rep Power
- 0
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?
- 04-20-2012, 02:25 AM #2
Re: Problems calling a class with constructor throws Exception
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.unreported exception Exception; must be caught or declared to be 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.
- 04-20-2012, 10:08 AM #3
Re: Problems calling a class with constructor throws Exception
Moved from Advanced Java. Please don't post beginner questions in that section.
dbWhy do they call it rush hour when nothing moves? - Robin Williams
- 04-20-2012, 10:10 AM #4
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.
dbWhy do they call it rush hour when nothing moves? - Robin Williams
- 04-22-2012, 09:22 PM #5
Member
- Join Date
- Mar 2012
- Location
- Malaysia
- Posts
- 18
- Rep Power
- 0
Similar Threads
-
Calling method from a different class into a constructor
By NewToJava_99 in forum New To JavaReplies: 1Last Post: 11-27-2011, 11:00 PM -
Calling on class with throws IOException
By gisler in forum NetworkingReplies: 5Last Post: 12-01-2009, 04:20 PM -
can I do this, throwing fnfe exception on class constructor?
By gcampton in forum New To JavaReplies: 11Last Post: 11-05-2009, 12:44 PM -
Calling constructor of parent class from a constructor
By Java Tip in forum Java TipReplies: 0Last Post: 12-19-2007, 09:10 AM -
Calling constructor of same class from a constructor
By Java Tip in forum Java TipReplies: 0Last Post: 12-19-2007, 09:01 AM


LinkBack URL
About LinkBacks
Reply With Quote
Bookmarks