Win a copy of Kotlin in Action this week in the Kotlin forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

trying to fix an unreported exception  RSS feed

 
Authur Edwards
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello, I don't know if the beginners forum is the right place for this but i will give it a go. I am having trouble trying to find the cause of this error message, "unreported exception NotEnoughMoney; must be caught or declared to be thrown" Line 315

I think i may have messed up the formating of the code, when i cut and pasted it into this post, hopefully you can make it out. I am presuming that this error is syntactic, and has something to do with the "withdraw_Action, or the transfer_Action methods near the bottom of the code.

Any help, in getting rid of this compiler method would be appreciated would be very much appreciated, very much. Sorry about the length of code included in the post


NB, this is for a educational course, but i don't think it violates any board rules to post something like this here?
cheerio









Also the following is the definition of the NotEnoughMoney exception, don't know if it is needed.

 
Abdul Rehman
Ranch Hand
Posts: 65
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,
The error you are getting is because you are calling a method which throws an unchecked exception, but, neither catch it nor declare it in the throws clause.
Since, I don't know which method is throwing the unchecked exception, I cannot help much. But, my suggestion is that you do the following.

Replace the following:

with:


Maybe, this will save you from the compiler error you are getting right now. But, if you use the above two methods anywhere else, be sure to sandwich the method call(s) between an appropriate try-catch clause.

Best regards,
Abdul Rehman.
[ January 20, 2007: Message edited by: Abdul Rehman ]
 
Eric Daly
Ranch Hand
Posts: 143
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello.
to me it looks like you are never throwing the exception (or not throwing it properly). I assume you should have a statement in your withdraw methods that throws the NotEnoughMoney exception if you try to withdraw too much. Also you need to declare that the method throws the exception (so that also includes the transfer() method). but you did not post code for your Savings and Credit classes, and that may help to clarify things.
[ January 20, 2007: Message edited by: Eric Daly ]
 
Authur Edwards
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
thank you for all the advice. I figured it was something to do with not throwing an exception, or something related. I have gotten the program to compile by adding the following to the transfer_Action method. I think it is okay, but i would still like advice on if i was right doing the changes.


The Changed method in MudvilleInterface


The above change seems to make the program compile.

Here are the savings and credit classes, if they are any help


And the credit class

 
Abdul Rehman
Ranch Hand
Posts: 65
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You sandwiched the code in the transfer_action() method between a try-catch block, which is akin to what I was saying. I think that this will solve the previous problem and I don't think it will raise any more problems.
Do you need help in any other thing?

Yours,
Abdul Rehman.
 
Authur Edwards
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Yes, i need help with one last problem, this time it is to do with the logic of the code. I fixed up most errors, this is a debugging exercise after all, but one annoying logic error keeps popping up.

This is the Account class



If you look at all the other classes I have posted, I am having trouble with the actual transfer_Action method, or something in the Savings class. when I hit the transfer button, it takes away money from the savings account, but fails to add it to the credit account, and the credit display value doesn't change. I might be asking for to much, but it would be good to get this logic error fixed. It is really annoying me.

I could possibly e-mail anyone all the corrected code.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!