v0.4.3a: added error reporting support to bundles
Not the most elegant solution, but it works all the same
This commit is contained in:
parent
0ca487094d
commit
ed21521670
|
@ -98,6 +98,7 @@ public class Bundle {
|
|||
Class cl = Class.forName( clName );
|
||||
return cl;
|
||||
} catch (ClassNotFoundException e) {
|
||||
reportException(e);
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
@ -125,10 +126,13 @@ public class Bundle {
|
|||
return null;
|
||||
}
|
||||
} catch (ClassNotFoundException e ) {
|
||||
reportException(e);
|
||||
return null;
|
||||
} catch (InstantiationException e ) {
|
||||
reportException(e);
|
||||
return null;
|
||||
} catch (IllegalAccessException e ) {
|
||||
reportException(e);
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
@ -141,6 +145,7 @@ public class Bundle {
|
|||
try {
|
||||
return Enum.valueOf( enumClass, data.getString( key ) );
|
||||
} catch (JSONException e) {
|
||||
reportException(e);
|
||||
return enumClass.getEnumConstants()[0];
|
||||
}
|
||||
}
|
||||
|
@ -155,6 +160,7 @@ public class Bundle {
|
|||
}
|
||||
return result;
|
||||
} catch (JSONException e) {
|
||||
reportException(e);
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
@ -169,6 +175,7 @@ public class Bundle {
|
|||
}
|
||||
return result;
|
||||
} catch (JSONException e) {
|
||||
reportException(e);
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
@ -183,6 +190,7 @@ public class Bundle {
|
|||
}
|
||||
return result;
|
||||
} catch (JSONException e) {
|
||||
reportException(e);
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
@ -201,11 +209,13 @@ public class Bundle {
|
|||
Class cl = Class.forName( clName );
|
||||
result[i] = cl;
|
||||
} catch (ClassNotFoundException e) {
|
||||
reportException(e);
|
||||
result[i] = null;
|
||||
}
|
||||
}
|
||||
return result;
|
||||
} catch (JSONException e) {
|
||||
reportException(e);
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
@ -221,7 +231,7 @@ public class Bundle {
|
|||
if (O != null) list.add( O );
|
||||
}
|
||||
} catch (JSONException e) {
|
||||
|
||||
reportException(e);
|
||||
}
|
||||
|
||||
return list;
|
||||
|
@ -231,7 +241,7 @@ public class Bundle {
|
|||
try {
|
||||
data.put( key, value );
|
||||
} catch (JSONException e) {
|
||||
|
||||
reportException(e);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -239,7 +249,7 @@ public class Bundle {
|
|||
try {
|
||||
data.put( key, value );
|
||||
} catch (JSONException e) {
|
||||
|
||||
reportException(e);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -247,7 +257,7 @@ public class Bundle {
|
|||
try {
|
||||
data.put( key, value );
|
||||
} catch (JSONException e) {
|
||||
|
||||
reportException(e);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -255,7 +265,7 @@ public class Bundle {
|
|||
try {
|
||||
data.put( key, value );
|
||||
} catch (JSONException e) {
|
||||
|
||||
reportException(e);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -263,7 +273,7 @@ public class Bundle {
|
|||
try {
|
||||
data.put( key, value );
|
||||
} catch (JSONException e) {
|
||||
|
||||
reportException(e);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -271,7 +281,7 @@ public class Bundle {
|
|||
try {
|
||||
data.put( key, value );
|
||||
} catch (JSONException e) {
|
||||
|
||||
reportException(e);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -279,7 +289,7 @@ public class Bundle {
|
|||
try {
|
||||
data.put( key, bundle.data );
|
||||
} catch (JSONException e) {
|
||||
|
||||
reportException(e);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -291,6 +301,7 @@ public class Bundle {
|
|||
object.storeInBundle( bundle );
|
||||
data.put( key, bundle.data );
|
||||
} catch (JSONException e) {
|
||||
reportException(e);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -300,6 +311,7 @@ public class Bundle {
|
|||
try {
|
||||
data.put( key, value.name() );
|
||||
} catch (JSONException e) {
|
||||
reportException(e);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -312,7 +324,7 @@ public class Bundle {
|
|||
}
|
||||
data.put( key, jsonArray );
|
||||
} catch (JSONException e) {
|
||||
|
||||
reportException(e);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -324,7 +336,7 @@ public class Bundle {
|
|||
}
|
||||
data.put( key, jsonArray );
|
||||
} catch (JSONException e) {
|
||||
|
||||
reportException(e);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -336,7 +348,7 @@ public class Bundle {
|
|||
}
|
||||
data.put( key, jsonArray );
|
||||
} catch (JSONException e) {
|
||||
|
||||
reportException(e);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -348,7 +360,7 @@ public class Bundle {
|
|||
}
|
||||
data.put( key, jsonArray );
|
||||
} catch (JSONException e) {
|
||||
|
||||
reportException(e);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -365,7 +377,7 @@ public class Bundle {
|
|||
try {
|
||||
data.put( key, array );
|
||||
} catch (JSONException e) {
|
||||
|
||||
reportException(e);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -394,6 +406,7 @@ public class Bundle {
|
|||
|
||||
return new Bundle( json );
|
||||
} catch (Exception e) {
|
||||
reportException(e);
|
||||
throw new IOException();
|
||||
}
|
||||
}
|
||||
|
@ -413,6 +426,7 @@ public class Bundle {
|
|||
|
||||
return true;
|
||||
} catch (IOException e) {
|
||||
reportException(e);
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
@ -420,4 +434,19 @@ public class Bundle {
|
|||
public static void addAlias( Class<?> cl, String alias ) {
|
||||
aliases.put( alias, cl.getName() );
|
||||
}
|
||||
|
||||
//This may be set in order to have bundles report exceptions
|
||||
//...Yes it would be far cleaner to have the bundling methods throw exceptions
|
||||
//But that would require too much code-changing right now.
|
||||
public static BundleExceptionCallback exceptionReporter;
|
||||
|
||||
private static void reportException(Throwable t){
|
||||
if (exceptionReporter != null){
|
||||
exceptionReporter.call(t);
|
||||
}
|
||||
}
|
||||
|
||||
public static abstract class BundleExceptionCallback {
|
||||
public abstract void call(Throwable t);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -163,6 +163,14 @@ public class ShatteredPixelDungeon extends Game {
|
|||
com.shatteredpixel.shatteredpixeldungeon.items.armor.glyphs.Repulsion.class,
|
||||
"com.shatteredpixel.shatteredpixeldungeon.items.armor.glyphs.Stench" );
|
||||
|
||||
com.watabou.utils.Bundle.exceptionReporter =
|
||||
new com.watabou.utils.Bundle.BundleExceptionCallback() {
|
||||
@Override
|
||||
public void call(Throwable t) {
|
||||
ShatteredPixelDungeon.reportException(t);
|
||||
}
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
@SuppressWarnings("deprecation")
|
||||
|
|
Loading…
Reference in New Issue
Block a user