Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Java Exception Handlering
#1
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
Reply
#2
import java.io.*?
Reply
#3
For all the io stuff...
Reply
#4
I mean try putting that in.
Reply
#5
It is.
Reply
#6
It says that the code in the try block will never throw a FileNotFound exception in the first place.
Reply
#7
Java is horrible!
Reply
#8
Reply
#9
(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.
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)