• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Exception never thrown....

 
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi all, wondering if someone could help me out here. I am getting the following error -
exception java.io.FileNotFoundException is never
thrown in body of corresponding try statement
catch (FileNotFoundException exception)
here is the code

If you need any more info let me know.
Thanks - Tom
 
Ranch Hand
Posts: 3451
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Tom,
Welcome to JavaRanch. Apparenly, the GameBoard(String) constructor isn't declared to throw FileNotFoundException.
 
Tom Williams
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi, thanks for the quick reply. Here is the GameBoard constructor -

All it does is call the parent class constructor with a suitable paramater. What else should it have?
As you can probably tell I am really new to java
 
Michael Morris
Ranch Hand
Posts: 3451
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
All it does is call the parent class constructor with a suitable paramater. What else should it have?
Well, what does the super constructor do? If you use a try block that catches a checked exception then some method or constructor must throw that checked excpetion or one of its children somewhere in the block. In your case, that doesn't seem to be what's going on. You could do this:

But that doesn't make a lot of sense unless the call to super(10) can throw that exception. The String (player) that you are passing into the GameBoard constructor is not even being used. I'm guessing that you are wanting to open some file with the name contained in player, in which case, a FileNotFoundException could be thrown.
 
Tom Williams
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Ok, i'll try to explain whats going on but it might not make too much sense given that I don't really understand it myself
GameBoard has two constructors, one for a filename typed at the command line and one for a player number if no filename is typed at the command line.
GameBoard is a subclass of Board, Board's function is to display a 10 by 10 grid type board. It has one constructor with an int passed in - super(10)
The main class checks for a filename typed at the command line with args[] (i think) If it doesn't find a filename then it goes ahead and creates a new GameBoard. If there was a filename typed at the command line it does the try/catch. If the filename was correct then it creates a new gameboard with the filename as a parameter. If the filename was incorrect(not found) it displays an error message and exits the program.
Hope that sheds some light on whats going on, let me know if you need anything else and thankyou for replying.
 
Michael Morris
Ranch Hand
Posts: 3451
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
OK, then you need to do something like this:

That still doesn't seem to fit into your main method or what you described in your last post: that GameBoard has two construtors, one that takes a file name and one for a player number. Instead of having your main method catch FileNotFoundException you probably want to check the file's existence there (just like in the above code) and if the file exists call the constructor that expects a file name otherwise call the other constructor.
 
Tom Williams
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I think i've got it, well it compiles anyways.
I didn't have
import java.io.*;
in the gameboard class so I put that in then added
throws IOException
to the constructor that has the filename passed to it.
So, it compiles which is a great leap forward for me, whether it does what it's supposed to do is another story
Thankyou very much for all your help, it is greatly appreciated.
Tom
 
Consider Paul's rocket mass heater.
reply
    Bookmark Topic Watch Topic
  • New Topic