Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Cleaned up Throwable try catches #3280

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
321 changes: 158 additions & 163 deletions src/main/java/bartworks/util/BWUtil.java

Large diffs are not rendered by default.

22 changes: 11 additions & 11 deletions src/main/java/gregtech/GTMod.java
Original file line number Diff line number Diff line change
Expand Up @@ -260,7 +260,7 @@ public void onPreLoad(FMLPreInitializationEvent aEvent) {
try {
tRunnable.run();
} catch (Throwable e) {
e.printStackTrace(GTLog.err);
GT_FML_LOGGER.error("Could not run Runnable in sBeforeGTPreload", e);
}
}

Expand Down Expand Up @@ -321,7 +321,7 @@ public void onPreLoad(FMLPreInitializationEvent aEvent) {
try {
tRunnable.run();
} catch (Throwable e) {
e.printStackTrace(GTLog.err);
GT_FML_LOGGER.error("Could not run Runnable in sAfterGTPreload", e);
}
}

Expand All @@ -340,7 +340,7 @@ public void onLoad(FMLInitializationEvent aEvent) {
try {
tRunnable.run();
} catch (Throwable e) {
e.printStackTrace(GTLog.err);
GT_FML_LOGGER.error("Could not run Runnable in sBeforeGTLoad", e);
}
}

Expand Down Expand Up @@ -392,7 +392,7 @@ public boolean test(ItemStack stack) {
try {
tRunnable.run();
} catch (Throwable e) {
e.printStackTrace(GTLog.err);
GT_FML_LOGGER.error("Could not run Runnable in sAfterGTLoad", e);
}
}
}
Expand All @@ -408,7 +408,7 @@ public void onPostLoad(FMLPostInitializationEvent aEvent) {
try {
tRunnable.run();
} catch (Throwable e) {
e.printStackTrace(GTLog.err);
GT_FML_LOGGER.error("Could not run Runnable in sBeforeGTPostload", e);
}
}

Expand Down Expand Up @@ -563,7 +563,7 @@ public void onPostLoad(FMLPostInitializationEvent aEvent) {
try {
tRunnable.run();
} catch (Throwable e) {
e.printStackTrace(GTLog.err);
GT_FML_LOGGER.error("Could not run Runnable in sAfterGTPostload", e);
}
}
GTPostLoad.addFakeRecipes();
Expand Down Expand Up @@ -600,7 +600,7 @@ public void onLoadComplete(FMLLoadCompleteEvent aEvent) {
try {
tRunnable.run();
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we please ditch some more of these random Throwable catches, especially the ones around the pre, post etc. Runnables.

I had a bitch of a time the other day trying to figure out why my code was seemingly doing nothing, only to realise that GT5U was silently catching otherwise useful exceptions. These runnables are used in many different places and this makes debugging them much more annoying.

} catch (Throwable e) {
e.printStackTrace(GTLog.err);
GT_FML_LOGGER.error("Could not run Runnable in sGTCompleteLoad", e);
}
}
GregTechAPI.sGTCompleteLoad = null;
Expand All @@ -624,7 +624,7 @@ public void onServerStarting(FMLServerStartingEvent aEvent) {
try {
tRunnable.run();
} catch (Throwable e) {
e.printStackTrace(GTLog.err);
GT_FML_LOGGER.error("Could not run Runnable in sBeforeGTServerstart", e);
}
}

Expand Down Expand Up @@ -759,7 +759,7 @@ public void onServerStarting(FMLServerStartingEvent aEvent) {
try {
tRunnable.run();
} catch (Throwable e) {
e.printStackTrace(GTLog.err);
GT_FML_LOGGER.error("Could not run Runnable in sAfterGTServerstart", e);
}
}

Expand Down Expand Up @@ -817,7 +817,7 @@ public void onServerStopping(FMLServerStoppingEvent aEvent) {
try {
tRunnable.run();
} catch (Throwable e) {
e.printStackTrace(GTLog.err);
GT_FML_LOGGER.error("Could not run Runnable in sBeforeGTServerstop", e);
}
}

Expand All @@ -827,7 +827,7 @@ public void onServerStopping(FMLServerStoppingEvent aEvent) {
try {
tRunnable.run();
} catch (Throwable e) {
e.printStackTrace(GTLog.err);
GT_FML_LOGGER.error("Could not run Runnable in sAfterGTServerstop", e);
}
}
// Interrupt IDLE Threads to close down cleanly
Expand Down
9 changes: 5 additions & 4 deletions src/main/java/gregtech/api/items/MetaBaseItem.java
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@

import com.gtnewhorizons.modularui.api.KeyboardUtil;

import gregtech.GTMod;
import gregtech.api.enums.SubTag;
import gregtech.api.interfaces.IItemBehaviour;
import gregtech.api.util.GTLanguageManager;
Expand Down Expand Up @@ -145,7 +146,7 @@ public boolean onLeftClickEntity(ItemStack aStack, EntityPlayer aPlayer, Entity
return false;
}
} catch (Throwable e) {
if (D1) e.printStackTrace(GTLog.err);
GTMod.GT_FML_LOGGER.error("Error left clicking entity", e);
}
return false;
}
Expand All @@ -167,7 +168,7 @@ public boolean onItemUse(ItemStack aStack, EntityPlayer aPlayer, World aWorld, i
return false;
}
} catch (Throwable e) {
if (D1) e.printStackTrace(GTLog.err);
GTMod.GT_FML_LOGGER.error("Error using item", e);
}
return false;
}
Expand Down Expand Up @@ -199,7 +200,7 @@ public boolean onItemUseFirst(ItemStack aStack, EntityPlayer aPlayer, World aWor
return false;
}
} catch (Throwable e) {
if (D1) e.printStackTrace(GTLog.err);
GTMod.GT_FML_LOGGER.error("Error using item", e);
}
return false;
}
Expand All @@ -213,7 +214,7 @@ public ItemStack onItemRightClick(ItemStack aStack, World aWorld, EntityPlayer a
if (tList != null) for (IItemBehaviour<MetaBaseItem> tBehavior : tList)
aStack = tBehavior.onItemRightClick(this, aStack, aWorld, aPlayer);
} catch (Throwable e) {
if (D1) e.printStackTrace(GTLog.err);
GTMod.GT_FML_LOGGER.error("Error right clicking item", e);
}
return aStack;
}
Expand Down
151 changes: 73 additions & 78 deletions src/main/java/gregtech/api/metatileentity/BaseMetaPipeEntity.java
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,6 @@
import gregtech.api.net.GTPacketTileEntity;
import gregtech.api.objects.GTItemStack;
import gregtech.api.util.CoverBehaviorBase;
import gregtech.api.util.GTLog;
import gregtech.api.util.GTModHandler;
import gregtech.api.util.GTOreDictUnificator;
import gregtech.api.util.GTUtility;
Expand Down Expand Up @@ -175,96 +174,92 @@ public void updateEntity() {
} else {
tTime = 0;
}
try {
if (hasValidMetaTileEntity()) {
if (mTickTimer++ == 0) {
oX = xCoord;
oY = yCoord;
oZ = zCoord;
if (isServerSide()) checkDropCover();
else {
requestCoverDataIfNeeded();
}
worldObj.markTileEntityChunkModified(xCoord, yCoord, zCoord, this);
mMetaTileEntity.onFirstTick(this);
if (!hasValidMetaTileEntity()) return;

if (hasValidMetaTileEntity()) {
if (mTickTimer++ == 0) {
oX = xCoord;
oY = yCoord;
oZ = zCoord;
if (isServerSide()) checkDropCover();
else {
requestCoverDataIfNeeded();
}
worldObj.markTileEntityChunkModified(xCoord, yCoord, zCoord, this);
mMetaTileEntity.onFirstTick(this);
if (!hasValidMetaTileEntity()) return;
}

if (isClientSide()) {
if (mColor != oColor) {
mMetaTileEntity.onColorChangeClient(oColor = mColor);
issueTextureUpdate();
}
if (isClientSide()) {
if (mColor != oColor) {
mMetaTileEntity.onColorChangeClient(oColor = mColor);
issueTextureUpdate();
}

if (mNeedsUpdate) {
worldObj.markBlockForUpdate(xCoord, yCoord, zCoord);
mNeedsUpdate = false;
}
if (mNeedsUpdate) {
worldObj.markBlockForUpdate(xCoord, yCoord, zCoord);
mNeedsUpdate = false;
}
if (isServerSide() && mTickTimer > 10) {
if (!doCoverThings()) return;

final byte oldConnections = mConnections;
// Mask-out connection direction bits to keep only Foam related connections
mConnections = (byte) (mMetaTileEntity.mConnections | (mConnections & ~IConnectable.CONNECTED_ALL));
// If foam not hardened, tries roll chance to harden
if ((mConnections & IConnectable.HAS_FOAM) == IConnectable.HAS_FRESHFOAM
&& getRandomNumber(1000) == 0) {
mConnections = (byte) ((mConnections & ~IConnectable.HAS_FRESHFOAM)
| IConnectable.HAS_HARDENEDFOAM);
}
if (mTickTimer > 12 && oldConnections != mConnections)
GregTechAPI.causeCableUpdate(worldObj, xCoord, yCoord, zCoord);
}
if (isServerSide() && mTickTimer > 10) {
if (!doCoverThings()) return;

final byte oldConnections = mConnections;
// Mask-out connection direction bits to keep only Foam related connections
mConnections = (byte) (mMetaTileEntity.mConnections | (mConnections & ~IConnectable.CONNECTED_ALL));
// If foam not hardened, tries roll chance to harden
if ((mConnections & IConnectable.HAS_FOAM) == IConnectable.HAS_FRESHFOAM
&& getRandomNumber(1000) == 0) {
mConnections = (byte) ((mConnections & ~IConnectable.HAS_FRESHFOAM)
| IConnectable.HAS_HARDENEDFOAM);
}
if (mTickTimer > 12 && oldConnections != mConnections)
GregTechAPI.causeCableUpdate(worldObj, xCoord, yCoord, zCoord);
}
mMetaTileEntity.onPreTick(this, mTickTimer);
if (!hasValidMetaTileEntity()) return;
if (isServerSide()) {
if (mTickTimer == 10) {
updateCoverBehavior();
issueBlockUpdate();
joinEnet();
}
mMetaTileEntity.onPreTick(this, mTickTimer);
if (!hasValidMetaTileEntity()) return;
if (isServerSide()) {
if (mTickTimer == 10) {
updateCoverBehavior();
issueBlockUpdate();
joinEnet();
}

if (xCoord != oX || yCoord != oY || zCoord != oZ) {
oX = xCoord;
oY = yCoord;
oZ = zCoord;
issueClientUpdate();
clearTileEntityBuffer();
}
if (xCoord != oX || yCoord != oY || zCoord != oZ) {
oX = xCoord;
oY = yCoord;
oZ = zCoord;
issueClientUpdate();
clearTileEntityBuffer();
}
}

mMetaTileEntity.onPostTick(this, mTickTimer);
if (!hasValidMetaTileEntity()) return;
mMetaTileEntity.onPostTick(this, mTickTimer);
if (!hasValidMetaTileEntity()) return;

if (isServerSide()) {
if (mTickTimer % 10 == 0) {
sendClientData();
}
if (isServerSide()) {
if (mTickTimer % 10 == 0) {
sendClientData();
}

if (mTickTimer > 10) {
if (mConnections != oTextureData) sendBlockEvent((byte) 0, oTextureData = mConnections);
byte tData = mMetaTileEntity.getUpdateData();
if (tData != oUpdateData) sendBlockEvent((byte) 1, oUpdateData = tData);
if (mColor != oColor) sendBlockEvent((byte) 2, oColor = mColor);
tData = (byte) (((mSidedRedstone[0] > 0) ? 1 : 0) | ((mSidedRedstone[1] > 0) ? 2 : 0)
| ((mSidedRedstone[2] > 0) ? 4 : 0)
| ((mSidedRedstone[3] > 0) ? 8 : 0)
| ((mSidedRedstone[4] > 0) ? 16 : 0)
| ((mSidedRedstone[5] > 0) ? 32 : 0));
if (tData != oRedstoneData) sendBlockEvent((byte) 3, oRedstoneData = tData);
}
if (mTickTimer > 10) {
if (mConnections != oTextureData) sendBlockEvent((byte) 0, oTextureData = mConnections);
byte tData = mMetaTileEntity.getUpdateData();
if (tData != oUpdateData) sendBlockEvent((byte) 1, oUpdateData = tData);
if (mColor != oColor) sendBlockEvent((byte) 2, oColor = mColor);
tData = (byte) (((mSidedRedstone[0] > 0) ? 1 : 0) | ((mSidedRedstone[1] > 0) ? 2 : 0)
| ((mSidedRedstone[2] > 0) ? 4 : 0)
| ((mSidedRedstone[3] > 0) ? 8 : 0)
| ((mSidedRedstone[4] > 0) ? 16 : 0)
| ((mSidedRedstone[5] > 0) ? 32 : 0));
if (tData != oRedstoneData) sendBlockEvent((byte) 3, oRedstoneData = tData);
}

if (mNeedsBlockUpdate) {
updateNeighbours(mStrongRedstone, oStrongRedstone);
oStrongRedstone = mStrongRedstone;
mNeedsBlockUpdate = false;
}
if (mNeedsBlockUpdate) {
updateNeighbours(mStrongRedstone, oStrongRedstone);
oStrongRedstone = mStrongRedstone;
mNeedsBlockUpdate = false;
}
}
} catch (Throwable e) {
e.printStackTrace();
e.printStackTrace(GTLog.err);
}

if (isServerSide() && hasTimeStatisticsStarted && hasValidMetaTileEntity()) {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
package gregtech.api.metatileentity.implementations;

import static gregtech.api.enums.GTValues.D1;
import static gregtech.api.enums.Textures.BlockIcons.MACHINE_BRONZEBRICKS_BOTTOM;
import static gregtech.api.enums.Textures.BlockIcons.MACHINE_BRONZEBRICKS_SIDE;
import static gregtech.api.enums.Textures.BlockIcons.MACHINE_BRONZEBRICKS_TOP;
Expand Down Expand Up @@ -38,7 +37,6 @@
import gregtech.api.objects.overclockdescriber.OverclockDescriber;
import gregtech.api.objects.overclockdescriber.SteamOverclockDescriber;
import gregtech.api.render.TextureFactory;
import gregtech.api.util.GTLog;
import gregtech.api.util.GTRecipe;
import gregtech.api.util.GTUtility;
import gregtech.api.util.WorldSpawnedEventBuilder.ParticleEventBuilder;
Expand Down Expand Up @@ -167,21 +165,17 @@ && getBaseMetaTileEntity().getCoverIDAtSide(getBaseMetaTileEntity().getFrontFaci
getBaseMetaTileEntity().getOffsetZ(getBaseMetaTileEntity().getFrontFacing(), 1))) {
sendSound((byte) 9);
mNeedsSteamVenting = false;
try {
for (EntityLivingBase tLiving : getBaseMetaTileEntity().getWorld()
.getEntitiesWithinAABB(
EntityLivingBase.class,
AxisAlignedBB.getBoundingBox(
getBaseMetaTileEntity().getOffsetX(getBaseMetaTileEntity().getFrontFacing(), 1),
getBaseMetaTileEntity().getOffsetY(getBaseMetaTileEntity().getFrontFacing(), 1),
getBaseMetaTileEntity().getOffsetZ(getBaseMetaTileEntity().getFrontFacing(), 1),
getBaseMetaTileEntity().getOffsetX(getBaseMetaTileEntity().getFrontFacing(), 1) + 1,
getBaseMetaTileEntity().getOffsetY(getBaseMetaTileEntity().getFrontFacing(), 1) + 1,
getBaseMetaTileEntity().getOffsetZ(getBaseMetaTileEntity().getFrontFacing(), 1) + 1))) {
GTUtility.applyHeatDamage(tLiving, getSteamDamage());
}
} catch (Throwable e) {
if (D1) e.printStackTrace(GTLog.err);
for (EntityLivingBase tLiving : getBaseMetaTileEntity().getWorld()
.getEntitiesWithinAABB(
EntityLivingBase.class,
AxisAlignedBB.getBoundingBox(
getBaseMetaTileEntity().getOffsetX(getBaseMetaTileEntity().getFrontFacing(), 1),
getBaseMetaTileEntity().getOffsetY(getBaseMetaTileEntity().getFrontFacing(), 1),
getBaseMetaTileEntity().getOffsetZ(getBaseMetaTileEntity().getFrontFacing(), 1),
getBaseMetaTileEntity().getOffsetX(getBaseMetaTileEntity().getFrontFacing(), 1) + 1,
getBaseMetaTileEntity().getOffsetY(getBaseMetaTileEntity().getFrontFacing(), 1) + 1,
getBaseMetaTileEntity().getOffsetZ(getBaseMetaTileEntity().getFrontFacing(), 1) + 1))) {
GTUtility.applyHeatDamage(tLiving, getSteamDamage());
}
}
return !mNeedsSteamVenting;
Expand Down
Loading
Loading