Clean up exception catching

This commit is contained in:
mezz committed 2016-03-04 01:42:17 -08:00
1 parent 5a78f97fcb
commit ec53b6d882
26 files changed
+71 -210

No files matched your search

@@ -19,11 +19,7 @@ import net.minecraftforge.fml.common.registry.VillagerRegistry.VillagerProfessio
public class VillageHandlerApiculture /*implements IVillageCreationHandler, IVillageTradeHandler*/ {
/*public static void registerVillageComponents() {
try {
MapGenStructureIO.func_143031_a(ComponentVillageBeeHouse.class, "Forestry:BeeHouse");
} catch (Throwable e) {
Log.severe("Failed to register village beehouse.");
}
MapGenStructureIO.registerStructureComponent(ComponentVillageBeeHouse.class, "Forestry:BeeHouse");
}
@SuppressWarnings("unchecked")
@@ -16,7 +16,6 @@ import java.util.List;
import net.minecraft.entity.Entity;
import net.minecraft.potion.Potion;
import net.minecraft.util.AxisAlignedBB;
import net.minecraft.util.BlockPos;
import net.minecraft.util.Vec3;
import forestry.api.apiculture.BeeManager;
@@ -103,21 +102,11 @@ public abstract class AlleleEffect extends AlleleCategorized implements IAlleleB
@Override
public IEffectData doFX(IBeeGenome genome, IEffectData storedData, IBeeHousing housing) {
Vec3 beeFXCoordinates = getFXCoordinates(housing);
Vec3 beeFXCoordinates = housing.getBeeFXCoordinates();
Proxies.render.addBeeHiveFX("particles/swarm_bee", housing.getWorld(), beeFXCoordinates.xCoord, beeFXCoordinates.yCoord, beeFXCoordinates.zCoord, genome.getPrimary().getSpriteColour(0));
return storedData;
}
protected Vec3 getFXCoordinates(IBeeHousing housing) {
try {
return housing.getBeeFXCoordinates();
} catch (Throwable error) {
// getBeeFXCoordinates() is only newly added to the API, fall back on getCoordinates()
BlockPos coordinates = housing.getCoordinates();
return new Vec3(coordinates.getX() + 0.5D, coordinates.getY() + 0.5D, coordinates.getZ() + 0.5D);
}
}
protected Vect getModifiedArea(IBeeGenome genome, IBeeHousing housing) {
IBeeModifier beeModifier = BeeManager.beeRoot.createBeeHousingModifier(housing);
float territoryModifier = beeModifier.getTerritoryModifier(genome, 1f);
@@ -68,7 +68,7 @@ public class AlleleEffectIgnition extends AlleleEffectThrottled {
if (housing.getWorld().rand.nextInt(2) != 0) {
super.doFX(genome, storedData, housing);
} else {
Vec3 beeFXCoordinates = getFXCoordinates(housing);
Vec3 beeFXCoordinates = housing.getBeeFXCoordinates();
Proxies.render.addEntityIgnitionFX(housing.getWorld(), beeFXCoordinates.xCoord, beeFXCoordinates.yCoord + 0.5, beeFXCoordinates.zCoord);
}
return storedData;
@@ -89,7 +89,7 @@ public class AlleleEffectPotion extends AlleleEffectThrottled {
if (housing.getWorld().rand.nextBoolean()) {
super.doFX(genome, storedData, housing);
} else {
Vec3 beeFXCoordinates = getFXCoordinates(housing);
Vec3 beeFXCoordinates = housing.getBeeFXCoordinates();
Proxies.render.addEntityPotionFX(housing.getWorld(), beeFXCoordinates.xCoord, beeFXCoordinates.yCoord + 0.5, beeFXCoordinates.zCoord, potionFXColor);
}
return storedData;
@@ -10,7 +10,6 @@
******************************************************************************/
package forestry.arboriculture.genetics.alleles;
import javax.annotation.Nonnull;
import java.util.Arrays;
import java.util.List;
@@ -145,21 +145,6 @@ public class PluginFluids extends BlankForestryPlugin {
FuelManager.generatorFuel.put(biomass.getFluid(), biomassFuel);
}
public static class MissingFluidException extends RuntimeException {
public MissingFluidException(String tag) {
super("Fluid '" + tag + "' was not found. Please check your configs.");
}
}
@Override
public void postInit() {
for (Fluids fluidType : Fluids.forestryFluids) {
if (fluidType.getFluid() == null && Config.isFluidEnabled(fluidType)) {
throw new MissingFluidException(fluidType.getTag());
}
}
}
public static class FillBucketHook {
@SubscribeEvent
public void fillBucket(FillBucketEvent event) {
@@ -114,8 +114,8 @@ public class MachineProperties<T extends TileForestry> implements IMachineProper
public TileEntity createTileEntity() {
try {
return teClass.getConstructor().newInstance();
} catch (Exception ex) {
throw new RuntimeException("Failed to instantiate tile entity of class " + teClass.getName());
} catch (ReflectiveOperationException e) {
throw new RuntimeException("Failed to instantiate tile entity of class " + teClass.getName(), e);
}
}
@@ -57,16 +57,12 @@ public class GuiSolderingIron extends GuiForestry<ContainerSolderingIron, ItemIn
fontRendererObj.drawString(description, guiLeft + 32, guiTop + 36 + row, fontColor.get("gui.screen"));
if (tube == null) {
try {
ICircuitSocketType socketType = layout.getSocketType();
if (CircuitSocketType.FARM.equals(socketType)) {
FarmDirection farmDirection = FarmDirection.values()[i];
String farmDirectionString = farmDirection.toString().toLowerCase(Locale.ENGLISH);
String localizedDirection = StringUtil.localize("gui.solder." + farmDirectionString);
fontRendererObj.drawString(localizedDirection, guiLeft + 17, guiTop + 36 + row, fontColor.get("gui.screen"));
}
} catch (Throwable ignored) {
// older circuit layouts do not have getSocketType()
ICircuitSocketType socketType = layout.getSocketType();
if (CircuitSocketType.FARM.equals(socketType)) {
FarmDirection farmDirection = FarmDirection.values()[i];
String farmDirectionString = farmDirection.toString().toLowerCase(Locale.ENGLISH);
String localizedDirection = StringUtil.localize("gui.solder." + farmDirectionString);
fontRendererObj.drawString(localizedDirection, guiLeft + 17, guiTop + 36 + row, fontColor.get("gui.screen"));
}
}
}
@@ -44,7 +44,7 @@ public class CommandHelpers {
if (world != null) {
return world;
}
} catch (Exception ex) {
} catch (NumberFormatException e) {
throwWrongUsage(sender, command);
}
}
@@ -34,6 +34,7 @@ import forestry.api.genetics.IAlleleSpecies;
import forestry.api.genetics.IBreedingTracker;
import forestry.core.config.Constants;
import forestry.core.proxy.Proxies;
import forestry.core.utils.Log;
import forestry.core.utils.StringUtil;
public final class CommandSaveStats extends SubCommand {
@@ -150,7 +151,7 @@ public final class CommandSaveStats extends SubCommand {
} catch (IOException ex) {
CommandHelpers.sendLocalizedChatMessage(sender, "for.chat.command.forestry.stats.save.error3");
ex.printStackTrace();
Log.error(StringUtil.localize("for.chat.command.forestry.stats.save.error3"), ex);
return;
}
@@ -13,7 +13,9 @@ package forestry.core.config;
import com.google.common.collect.LinkedListMultimap;
import java.io.File;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.util.ArrayList;
@@ -199,7 +201,7 @@ public class Config {
String[] stamps = configCommon.getStringListLocalized("crafting.stamps", "disabled", defaultCollectors, allStamps);
try {
collectorStamps.addAll(Arrays.asList(stamps));
} catch (Exception ex) {
} catch (RuntimeException ex) {
Log.warning("Failed to read config for 'crafting.stamps.disabled', setting to default.");
Property property = configCommon.get("crafting.stamps", "disabled", defaultCollectors);
property.setToDefault();
@@ -287,8 +289,10 @@ public class Config {
while ((readBytes = stream.read(buffer)) > 0) {
outstream.write(buffer, 0, readBytes);
}
} catch (Exception ex) {
ex.printStackTrace();
} catch (FileNotFoundException e) {
Log.error("File not found.", e);
} catch (IOException e) {
Log.error("Failed to copy file.", e);
}
}
@@ -299,8 +303,8 @@ public class Config {
try {
InputStream hintStream = Config.class.getResourceAsStream("/config/forestry/hints.properties");
prop.load(hintStream);
} catch (Exception ex) {
ex.printStackTrace();
} catch (IOException e) {
Log.error("Failed to load hints file.", e);
}
for (String key : prop.stringPropertyNames()) {
@@ -12,6 +12,7 @@ package forestry.core.fluids;
import javax.annotation.Nonnull;
import java.awt.Color;
import java.io.IOException;
import java.util.Collections;
import java.util.EnumSet;
import java.util.HashMap;
@@ -418,7 +419,7 @@ public enum Fluids {
ResourceLocation resourceLocation = new ResourceLocation(Constants.ID, "blocks/liquid/" + getTag() + "_flow");
IResourceManager resourceManager = Proxies.common.getClientInstance().getResourceManager();
return resourceManager.getResource(resourceLocation) != null;
} catch (java.lang.Exception e) {
} catch (IOException e) {
return false;
}
}
@@ -51,12 +51,8 @@ public class ContainerSocketedHelper<T extends TileEntity & ISocketable> impleme
return;
}
try {
if (!tile.getSocketType().equals(circuitBoard.getSocketType())) {
return;
}
} catch (Throwable ignored) {
// older circuitBoards don't have getSocketType()
if (!tile.getSocketType().equals(circuitBoard.getSocketType())) {
return;
}
ItemStack toSocket = itemstack.copy();
@@ -26,6 +26,7 @@ import net.minecraft.item.ItemStack;
import net.minecraft.util.BlockPos;
import net.minecraft.util.EnumFacing;
import net.minecraft.world.IBlockAccess;
import net.minecraftforge.client.model.IFlexibleBakedModel;
import net.minecraftforge.client.model.ISmartBlockModel;
import net.minecraftforge.client.model.ISmartItemModel;
@@ -189,7 +190,7 @@ public abstract class ModelBlockOverlay<B extends Block> implements IFlexibleBak
baker.setRenderBoundsFromBlock(block);
try {
backeWorldBlock(bBlock, world, pos, baker);
} catch (Exception e) {
} catch (RuntimeException e) {
return null;
}
@@ -209,7 +210,7 @@ public abstract class ModelBlockOverlay<B extends Block> implements IFlexibleBak
baker.setRenderBoundsFromBlock(block);
try {
backeInventoryBlock(bBlock, stack, baker);
} catch (Exception e) {
} catch (RuntimeException e) {
return null;
}
@@ -49,6 +49,7 @@ import net.minecraftforge.fml.relauncher.Side;
import net.minecraftforge.fml.relauncher.SideOnly;
import forestry.core.items.ItemCrated;
import forestry.core.utils.Log;
import forestry.core.utils.StringUtil;
import forestry.storage.PluginStorage;
@@ -112,7 +113,7 @@ public class ModelCrate implements ISmartItemModel {
ModelBlock modelblock = p_177581_1_.getRootModel();
return modelblock == MODEL_GENERATED || modelblock == MODEL_COMPASS || modelblock == MODEL_CLOCK;
}
} catch (Exception e) {
} catch (IOException e) {
return false;
}
}
@@ -148,7 +149,11 @@ public class ModelCrate implements ISmartItemModel {
modelblock.name = p_177594_1_.toString();
model = modelblock;
} finally {
reader.close();
try {
reader.close();
} catch (IOException e) {
Log.error("Failed to close crate model reader.", e);
}
}
if (model != null && model.getParentLocation() != null) {
@@ -79,7 +79,7 @@ public class DataInputStreamForestry extends DataInputStream {
T streamable = streamableClass.newInstance();
streamable.readData(this);
return streamable;
} catch (ReflectiveOperationException e) {
} catch (IllegalAccessException | InstantiationException | IOException e) {
throw new InvalidObjectException("Failed to read Streamable for class " + streamableClass + " with error " + e);
}
}
@@ -16,6 +16,8 @@ import net.minecraft.network.PacketBuffer;
import net.minecraftforge.fml.common.network.internal.FMLProxyPacket;
import forestry.core.utils.Log;
import io.netty.buffer.ByteBufOutputStream;
import io.netty.buffer.Unpooled;
@@ -31,7 +33,7 @@ public abstract class ForestryPacket implements IForestryPacket {
data.writeByte(id.ordinal());
writeData(data);
} catch (IOException e) {
e.printStackTrace();
Log.error("Failed to write packet.", e);
}
return new FMLProxyPacket(new PacketBuffer(buf.buffer()), PacketHandler.channelId);
@@ -10,6 +10,7 @@
******************************************************************************/
package forestry.core.network;
import java.io.IOException;
import java.io.InputStream;
import net.minecraft.entity.player.EntityPlayer;
@@ -24,6 +25,7 @@ import net.minecraftforge.fml.common.network.NetworkRegistry;
import net.minecraftforge.fml.common.network.internal.FMLProxyPacket;
import forestry.core.proxy.Proxies;
import forestry.core.utils.Log;
import io.netty.buffer.ByteBufInputStream;
@@ -47,8 +49,8 @@ public class PacketHandler {
IForestryPacketServer packetHandler = packetId.getPacketHandler();
packetHandler.readData(data);
packetHandler.onPacketData(data, player);
} catch (Exception ex) {
ex.printStackTrace();
} catch (IOException e) {
Log.error("Failed to read packet.", e);
}
}
@@ -63,8 +65,8 @@ public class PacketHandler {
IForestryPacketClient packetHandler = packetId.getPacketHandler();
packetHandler.readData(data);
packetHandler.onPacketData(data, player);
} catch (Exception ex) {
ex.printStackTrace();
} catch (IOException e) {
Log.error("Failed to read packet.", e);
}
}
@@ -74,9 +74,8 @@ public abstract class RecipeUtil {
try {
return getShapedRecipeAsArray(recipe.getWidth(), recipe.getHeight(), recipe.getIngredients(), recipe.getRecipeOutput());
} catch (Exception ex) {
Log.warning("Exception while trying to parse an ItemStack[10] from an IRecipe:");
Log.warning(ex.getMessage());
} catch (RuntimeException ex) {
Log.warning("Exception while trying to parse an ItemStack[10] from an IRecipe:", ex);
}
return null;
@@ -10,11 +10,14 @@
******************************************************************************/
package forestry.core.render;
import java.io.IOException;
import java.io.InputStream;
import java.util.Properties;
import net.minecraft.client.resources.IResourceManager;
import forestry.core.utils.Log;
public class FontColour {
//private static final ResourceLocation colourDefinitions = new ForestryResource("/config/forestry/colour.properties");
@@ -41,8 +44,8 @@ public class FontColour {
//if (fontStream != null)
// fontStream.close();
defaultFontStream.close();
} catch (Exception e) {
e.printStackTrace();
} catch (IOException e) {
Log.error("Failed to load font colors.", e);
}
}
@@ -53,7 +53,7 @@ public class ForestryModEnvWarningCallable implements ICrashCallable {
@Nonnull
@Override
public String call() throws Exception {
public String call() {
return disabledModulesMessage;
}
@@ -215,7 +215,7 @@ public class PluginFarming extends BlankForestryPlugin {
try {
Block sapling = ItemStackUtil.getBlockFromRegistry(saplingString);
if (sapling == null || sapling == Blocks.air) {
throw new RuntimeException("can't find block for " + saplingString);
throw new IllegalArgumentException("can't find block for " + saplingString);
}
int saplingMeta = Integer.parseInt(saplingMetaString);
@@ -224,15 +224,15 @@ public class PluginFarming extends BlankForestryPlugin {
} else {
Item windfall = ItemStackUtil.getItemFromRegistry(windfallString);
if (windfall == null) {
throw new RuntimeException("can't find item for " + windfallString);
throw new IllegalArgumentException("can't find item for " + windfallString);
}
ItemStack windfallStack = new ItemStack(windfall, 1, Integer.parseInt(windfallMetaString));
farmables.add(new FarmableGenericSapling(sapling, saplingMeta, windfallStack));
}
} catch (Exception ex) {
Log.warning("%s for farm '%s': %s", errormsg, tokens[0], ex.getMessage());
} catch (IllegalArgumentException e) {
Log.warning("%s for farm '%s'", errormsg, tokens[0], e.getMessage());
}
return true;
@@ -259,19 +259,19 @@ public class PluginFarming extends BlankForestryPlugin {
try {
Item seed = ItemStackUtil.getItemFromRegistry(items[0]);
if (seed == null) {
throw new RuntimeException("can't find item for " + items[0]);
throw new IllegalArgumentException("can't find item for " + items[0]);
}
Block crop = ItemStackUtil.getBlockFromRegistry(items[2]);
if (crop == null || crop == Blocks.air) {
throw new RuntimeException("can't find block for " + items[2]);
throw new IllegalArgumentException("can't find block for " + items[2]);
}
Farmables.farmables.get(tokens[0]).add(
new FarmableGenericCrop(new ItemStack(seed, 1, Integer.parseInt(items[1])),
crop,
Integer.parseInt(items[3])));
} catch (Exception ex) {
Log.warning("%s for farm '%s': %s", errormsg, tokens[0], ex.getMessage());
} catch (IllegalArgumentException e) {
Log.warning("%s for farm '%s': %s", errormsg, tokens[0], e.getMessage());
}
return true;
@@ -53,15 +53,12 @@ public class CircuitFarmLogic extends Circuit {
IFarmLogic logic;
try {
logic = logicClass.getConstructor(IFarmHousing.class).newInstance(housing);
} catch (Exception ex) {
throw new RuntimeException("Failed to instantiate logic of class " + logicClass.getName() + ": " + ex.getMessage());
} catch (ReflectiveOperationException ex) {
throw new RuntimeException("Failed to instantiate logic of class " + logicClass.getName() + ": " + ex.getMessage(), ex);
}
try {
logic.setManual(isManual);
} catch (Throwable e) {
// uses older version of the API that doesn't implement setManual
}
logic.setManual(isManual);
housing.setFarmLogic(FarmDirection.values()[slot], logic);
}
@@ -12,6 +12,7 @@ package forestry.storage;
import java.awt.Color;
import java.io.File;
import java.io.IOException;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
@@ -583,8 +584,8 @@ public class PluginStorage extends BlankForestryPlugin {
ModelCrate.MODEL_COMPASS = ObfuscationReflectionHelper.getPrivateValue(ModelBakery.class, event.modelLoader, 15);
ModelCrate.MODEL_CLOCK = ObfuscationReflectionHelper.getPrivateValue(ModelBakery.class, event.modelLoader, 16);
ModelCrate.loader = event.modelLoader;
} catch (Exception e) {
e.printStackTrace();
} catch (IOException e) {
Log.error("Failed to bake model.", e);
}
}
}