This week's book giveaway is in the OCAJP 8 forum. We're giving away four copies of OCA Java SE 8 Programmer I Study Guide and have Edward Finegan & Robert Liguori on-line! See this thread for details.
I've been tidying up my code and creating the relevant javadoc comments and i've realised I haven't wrote a great deal of exception handling.
Its always been an area which has confused me slightly and i'm looking for a little advice on what is standard practice.
As far as I can see the only real errors which will occur in my program will be the file i'm reading from not existing and possibly mis placed values in a file so I might try and create a double from a string etc.
These all seem to be IOExceptions and all through my code I have thrown IOExceptions from methods etc.
Now I need to catch them is there a simple way to put a single catch statement in the "topmost" calling class which simply closes the program and outputs a single line to the console highlighting the error?
This will tell the function that calls openFile that this funtion throws an IOExceotion which needs to be handled leaving the option to wrap this call with a try/catch or pass it "upwards" in the same way. You can keep throwing up untill you reach your upmost function and wrap this with a try catch.
With regard to using exceptions elsewhere in your code you may consider using them yourself where unexpected events occurs. You don't just have to catch the exceptions that the SDK functions throw to you!