• Post Reply Bookmark Topic Watch Topic
  • New Topic

User Defined Packages  RSS feed

 
Zhuge Liang
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I'm working on a final project and i cant seem to compile my package.
my teacher used a switch in the javac command that worked last week but i didnt write it down and kinda forgot.. anyone know of a switch that might work. it was something like...
javac (something) \banking
alright.. i got the thing to compile.. heres another problem..
my class is throwing an exception and handling it but when i compile it says that the exception is not being handled at all.. heres code snippets from where im having problems..
this is the base class

heres the extended class's code

if the exception is handled in the superconstructor.. why in god's name would it need to be handled in the constructor also? .. i've tried to implement a try catch block in my constructor but you cant do that with a super(), it gives a "super() must be the first line of constructor" horse feces.. this project is annoying me to no end. i cant wait til java is over and i can move back to my old ways.
[ November 24, 2003: Message edited by: Zhuge Liang ]
 
Joel McNary
Bartender
Posts: 1840
Eclipse IDE Java Ruby
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The code that you show here should work fine; what code is calling the constructor?
The problem here is that, while you are indeed handling the error in the super constructor, you are also declaring that the superconstructor throws the error. Note that the super constructor doesn't actually throw it; it just says that it does.
Since javac sees that the superconstructor might possibly throw the exception (because you declared that the constructor can throw it; even if it doesn't now, it might in the future), it insists that anything that calls that constructor either:
a). handle the exception, or
b). throw the exception.
In this case, it strikes me that you don't really want to catch the exception that you throw in the superconstructor; that doesn't seem to be the level at which the exception should be handled. You want to force whatever code called the constructor to handle the exception. Simply remove the try/catch block from the superconstructor and you should be fine.
BTW, it rarely makes sense to catch an exception in the same method in which you throw it--there are less expensive ways to transfer the flow from one part to another (if statements, for example...)
 
Zhuge Liang
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

BTW, it rarely makes sense to catch an exception in the same method in which you throw it--there are less expensive ways to transfer the flow from one part to another (if statements, for example...)

i know.. but our teacher wanted us to use exceptions in this. i personally would have used if statements... thanks for the help
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!