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

throws ExceptionIO error  RSS feed

 
Sarah Singh
Greenhorn
Posts: 12
1
C++
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator




I am trying to run this code but I am getting error in line "throw io.IOException;"(line 11) I have downloaded the TextIO file...I am not sure how to debug this,
Any help will be greatly appreciated ^.^
 
Jeanne Boyarsky
author & internet detective
Sheriff
Posts: 37234
519
Eclipse IDE Java VI Editor
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
That code should be



This tells Java that the method might (or might not) throw an IOException when running.
 
Debdeep Ganguly
Greenhorn
Posts: 16
Android IntelliJ IDE Java
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I don't have any idea what you did with the line but as far as i know, surrounding the statement with a try catch or adding to your main method signature will definitely make it work.
 
Sarah Singh
Greenhorn
Posts: 12
1
C++
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
@Jeanne Boyarsky

Gotchya! Thanks for clarifying that When I apply the edits,I think it goes into an infinite loop...since its not producing any output...unless I am doing something wrong :\



===========================================================================================
@Debdeep Ganguly

Yes! The code works with the suggested ammendment! Although I do not get the expected results

-------------------------------
Expected output

Help on:
1. if
2. switch
3. while
4. do-while
5. for
Choose one:
4
The do-while
do{
statement;
}while(condition);

--------------------------------------
Output after suggested ammendment

Help on:
if:
switch:
while:
do - while:
for
:
choose one:
 
Knute Snortum
Sheriff
Posts: 4073
112
Chrome Eclipse IDE Java Postgres Database VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
What could you do to get the expected results?
 
Norm Radder
Ranch Foreman
Posts: 2240
28
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Safe programming note: When coding a switch statement ALWAYS have a default: case that prints out a message saying what is wrong and shows the invalid input.
 
Campbell Ritchie
Marshal
Posts: 55698
163
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Welcome to the Ranch

Don't use System.in.read(). It is a really awkward method to use. Try a Scanner, and you can use the words as options in the switch statement.
 
Sarah Singh
Greenhorn
Posts: 12
1
C++
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks everyone who looked into my problem ^.^ And thanks for all the suggestions <3
This is really silly, but I realized thatsome of my print statements are wrong which is why I am not getting expected output D:
Sorry about that :'( Also, there was a bug in java.io.IOException Line which in now fixed \(^.^)/
Regards

Editted Code


 
Henry Wong
author
Sheriff
Posts: 23283
125
C++ Chrome Eclipse IDE Firefox Browser Java jQuery Linux VI Editor Windows
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Thanks for providing your solution ... have a cow.

Henry
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!