v0.8.0b: improved how GdxRuntimeExceptions are handled in FileUtils

This commit is contained in:
Evan Debenham
2020-05-05 12:36:20 -04:00
parent 6698d97ce2
commit fc1b87bfa1

View File

@@ -26,7 +26,6 @@ import com.badlogic.gdx.Gdx;
import com.badlogic.gdx.files.FileHandle;
import com.badlogic.gdx.utils.GdxRuntimeException;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
@@ -100,11 +99,12 @@ public class FileUtils {
//only works for base path
public static Bundle bundleFromFile( String fileName ) throws IOException{
try {
FileHandle file = getFileHandle( fileName );
if (!file.exists()){
throw new FileNotFoundException("file not found: " + file.path());
} else {
return bundleFromStream(file.read());
} catch (GdxRuntimeException e){
//game classes expect an IO exception, so wrap the GDX exception in that
throw new IOException(e);
}
}
@@ -121,12 +121,8 @@ public class FileUtils {
try {
bundleToStream(getFileHandle( fileName ).write(false), bundle);
} catch (GdxRuntimeException e){
if (e.getCause() instanceof IOException){
//we want to throw the underlying IOException, not the GdxRuntimeException
throw (IOException)e.getCause();
} else {
throw e;
}
//game classes expect an IO exception, so wrap the GDX exception in that
throw new IOException(e);
}
}