v0.8.0b: improved how GdxRuntimeExceptions are handled in FileUtils
This commit is contained in:
@@ -26,7 +26,6 @@ import com.badlogic.gdx.Gdx;
|
|||||||
import com.badlogic.gdx.files.FileHandle;
|
import com.badlogic.gdx.files.FileHandle;
|
||||||
import com.badlogic.gdx.utils.GdxRuntimeException;
|
import com.badlogic.gdx.utils.GdxRuntimeException;
|
||||||
|
|
||||||
import java.io.FileNotFoundException;
|
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.io.InputStream;
|
import java.io.InputStream;
|
||||||
import java.io.OutputStream;
|
import java.io.OutputStream;
|
||||||
@@ -100,11 +99,12 @@ public class FileUtils {
|
|||||||
|
|
||||||
//only works for base path
|
//only works for base path
|
||||||
public static Bundle bundleFromFile( String fileName ) throws IOException{
|
public static Bundle bundleFromFile( String fileName ) throws IOException{
|
||||||
FileHandle file = getFileHandle( fileName );
|
try {
|
||||||
if (!file.exists()){
|
FileHandle file = getFileHandle( fileName );
|
||||||
throw new FileNotFoundException("file not found: " + file.path());
|
|
||||||
} else {
|
|
||||||
return bundleFromStream(file.read());
|
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 {
|
try {
|
||||||
bundleToStream(getFileHandle( fileName ).write(false), bundle);
|
bundleToStream(getFileHandle( fileName ).write(false), bundle);
|
||||||
} catch (GdxRuntimeException e){
|
} catch (GdxRuntimeException e){
|
||||||
if (e.getCause() instanceof IOException){
|
//game classes expect an IO exception, so wrap the GDX exception in that
|
||||||
//we want to throw the underlying IOException, not the GdxRuntimeException
|
throw new IOException(e);
|
||||||
throw (IOException)e.getCause();
|
|
||||||
} else {
|
|
||||||
throw e;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user