Results 1 to 5 of 5
- 09-23-2012, 02:45 AM #1
Member
- Join Date
- Feb 2011
- Posts
- 33
- Rep Power
- 0
Calling a private method with an exception in a constructor
Hello I am having trouble calling a private method in my constructor. I have a private method called "dostuff()" that has an exception. I then called the method in my constructor "this.dostuff()" and I got and error saying "unreported exception java.lang.Exception; must be caught or declared to be thrown". Can someone give me insight on what to do, I'll really appreciate it.
- 09-23-2012, 03:39 AM #2
Moderator
- Join Date
- Feb 2009
- Location
- New Zealand
- Posts
- 4,545
- Rep Power
- 11
Re: Calling a private method with an exception in a constructor
If doStuff() is declared to throw an exception then any method or constructor that calls it must either (A) do the call within a try/catch block or (B) that other method or constructor must also declare itself to throw the exception. Those are your options. See The Catch or Specify Requirement (The Java™ Tutorials > Essential Classes > Exceptions)
- 09-23-2012, 11:30 PM #3
Member
- Join Date
- Feb 2011
- Posts
- 33
- Rep Power
- 0
Re: Calling a private method with an exception in a constructor
could you do a small example of those conditions?
Last edited by Fubarable; 09-23-2012 at 11:42 PM.
-
Re: Calling a private method with an exception in a constructor
Please click on the link that pbrockway provided as there you'll find explanation and examples.
- 09-24-2012, 12:08 AM #5
Moderator
- Join Date
- Feb 2009
- Location
- New Zealand
- Posts
- 4,545
- Rep Power
- 11
Re: Calling a private method with an exception in a constructor
... and if there is something *specific* about what you find there that you can't understand, ask about that.
No-one is pretending that technical tutorials are easy to read, nor are we trying to ignore your question. But the fact is that Oracle's Tutorial has had a lot of close editorial attention paid to it, over a long time. Anything I might write off the top of my head would be, at best, an "explanation-lite".
Similar Threads
-
Problems calling a class with constructor throws Exception
By brrrr in forum New To JavaReplies: 4Last Post: 04-22-2012, 09:22 PM -
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 -
Private constructor and super()
By Basit56 in forum Advanced JavaReplies: 9Last Post: 08-21-2009, 06:19 AM -
[SOLVED] Accessing private constructor
By piyu.sha in forum New To JavaReplies: 2Last Post: 10-06-2008, 05:45 AM -
Calling constructor of parent class from a constructor
By Java Tip in forum Java TipReplies: 0Last Post: 12-19-2007, 09:10 AM


1Likes
LinkBack URL
About LinkBacks
Reply With Quote

Bookmarks