• Post Reply Bookmark Topic Watch Topic
  • New Topic

Try-Catch Handling  RSS feed

 
Greenhorn
Posts: 13
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I'm making this program to read a file line by line using BufferedReader and after reading each line it checks for validity of each section of it. If an exception is found it catches it properly and such. However, my problem is that I want it to continue until the end of the file as opposed to stopping after the first error. I know there is *resumption* handling but I can't figure out a way to do that.

To try and get the resumption working, I put it in a loop and when the it reaches the end of the file it sets a boolean to true and thus should end the loop, but the loop keeps going after each exception and repeats until the error in an infinite loop.

It's relatively long code, but if you need it let me know.
 
Bartender
Posts: 1638
IntelliJ IDE Java MySQL Database
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Are you sure that the boolean flag is getting set.
Try putting print statements before and after setting the flag.
 
Rancher
Posts: 3742
16
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You shouldn't need to set a flag. Try something like this

[ March 26, 2008: Message edited by: Joanne Neal ]
 
Ranch Hand
Posts: 457
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
as per Joanne, the try/catch just needs to be inside the loop,
 
Phill McElroy
Greenhorn
Posts: 13
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks guys,

You were right, and I had tried it before but the flow for the execution was a little messed so it didn't quite work properly.. I had to add another try-catch and put the whole loop and string processing try-catch inside it (For the file reading exception handling)...

I'd like to say all is good now but I still have to work out all the ways to catch the friggen exceptions!
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!