2DWorlds Forums
Java Exception Handlering - Printable Version

+- 2DWorlds Forums (http://2dworlds.buildism.net/forum)
+-- Forum: Off Topic (http://2dworlds.buildism.net/forum/forumdisplay.php?fid=5)
+--- Forum: Programming (http://2dworlds.buildism.net/forum/forumdisplay.php?fid=30)
+--- Thread: Java Exception Handlering (/showthread.php?tid=8624)



Java Exception Handlering - Dignity - 11-23-2011

Here's a little piece of my game code.

Code:
try {
    assetManager.registerLocator("map.zip", ZipLocator.class.getName());
    sceneModel = assetManager.loadModel("main.scene");
    sceneModel.setLocalScale(2f);
    }
    catch (FileNotFoundException e) {
        System.err.println("ERROR: file not found.");
        
    }


Whats causing the error is the catch, it says.

Java Compiler Wrote:exception java.io.FileNotFoundException is never thrown in body of corresponding try statement



RE: Java Exception Handlering - Mustachio - 11-23-2011

import java.io.*?


RE: Java Exception Handlering - Dignity - 11-23-2011

For all the io stuff...


RE: Java Exception Handlering - Mustachio - 11-23-2011

I mean try putting that in.


RE: Java Exception Handlering - Dignity - 11-23-2011

It is.


RE: Java Exception Handlering - noob007 - 11-23-2011

It says that the code in the try block will never throw a FileNotFound exception in the first place.


RE: Java Exception Handlering - Colin608 - 11-23-2011

Java is horrible!



RE: Java Exception Handlering - noob007 - 11-23-2011




RE: Java Exception Handlering - Jacob__mybb_import1 - 11-23-2011

(11-23-2011, 02:58 PM)roperson Wrote: Here's a little piece of my game code.

Code:
try {
    assetManager.registerLocator("map.zip", ZipLocator.class.getName());
    sceneModel = assetManager.loadModel("main.scene");
    sceneModel.setLocalScale(2f);
    }
    catch (FileNotFoundException e) {
        System.err.println("ERROR: file not found.");
        
    }


Whats causing the error is the catch, it says.

Java Compiler Wrote:exception java.io.FileNotFoundException is never thrown in body of corresponding try statement

The loadModel() function throws a kind of RuntimeException (I can't remember which one) if it can't find what you're trying to load. RuntimeExceptions are unchecked, meaning you don't have to catch them, but they will end your program.