Skip to content

Commit 200779f

Browse files
authored
remove catch throwable where possible (#2742)
1 parent dd350a2 commit 200779f

File tree

5 files changed

+15
-15
lines changed

5 files changed

+15
-15
lines changed

src/main/java/gregtech/client/particle/GTParticleManager.java

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -142,10 +142,10 @@ public void renderParticles(@NotNull Entity renderViewEntity, float partialTicks
142142

143143
private static void renderGlParticlesInLayer(@NotNull Map<@Nullable IRenderSetup, ArrayDeque<GTParticle>> renderQueue,
144144
@NotNull EffectRenderContext context) {
145-
for (var e : renderQueue.entrySet()) {
145+
for (var entry : renderQueue.entrySet()) {
146146
@Nullable
147-
IRenderSetup handler = e.getKey();
148-
ArrayDeque<GTParticle> particles = e.getValue();
147+
IRenderSetup handler = entry.getKey();
148+
ArrayDeque<GTParticle> particles = entry.getValue();
149149
if (particles.isEmpty()) continue;
150150

151151
boolean initialized = false;
@@ -160,8 +160,8 @@ private static void renderGlParticlesInLayer(@NotNull Map<@Nullable IRenderSetup
160160
}
161161
}
162162
particle.renderParticle(buffer, context);
163-
} catch (Throwable throwable) {
164-
GTLog.logger.error("particle render error: {}", particle.toString(), throwable);
163+
} catch (RuntimeException e) {
164+
GTLog.logger.error("particle render error: {}", particle.toString(), e);
165165
particle.setExpired();
166166
}
167167
}

src/main/java/gregtech/common/covers/facade/FacadeHelper.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -52,15 +52,15 @@ public static IBlockState lookupBlockForItem(ItemStack itemStack) {
5252
}
5353

5454
private static IBlockState lookupBlockForItemUnsafe(ItemStack itemStack) {
55-
if (!(itemStack.getItem() instanceof ItemBlock)) {
55+
if (!(itemStack.getItem() instanceof ItemBlock itemBlock)) {
5656
return null;
5757
}
58-
Block block = ((ItemBlock) itemStack.getItem()).getBlock();
58+
Block block = itemBlock.getBlock();
5959
int blockMetadata = itemStack.getItem().getMetadata(itemStack);
6060
try {
6161
// noinspection deprecation
6262
return block.getStateFromMeta(blockMetadata);
63-
} catch (Throwable e) {
63+
} catch (RuntimeException e) {
6464
return null;
6565
}
6666
}

src/main/java/gregtech/common/gui/widget/monitor/WidgetCoverList.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -92,8 +92,8 @@ public boolean mouseClicked(int mouseX, int mouseY, int button) {
9292
if (!result && mouseY >= this.getPosition().y && mouseY <= this.getPosition().y + this.getSize().height) {
9393
Widget widget = this.widgets.stream().filter(it -> it.isMouseOverElement(mouseX, mouseY)).findFirst()
9494
.orElse(null);
95-
if (widget instanceof WidgetGroup) {
96-
List<Widget> children = ((WidgetGroup) widget).getContainedWidgets(true);
95+
if (widget instanceof WidgetGroup wg) {
96+
List<Widget> children = wg.getContainedWidgets(true);
9797
if (children.get(0).isMouseOverElement(mouseX, mouseY)) {
9898
try {
9999
String posString = ObfuscationReflectionHelper.getPrivateValue(LabelWidget.class,
@@ -108,7 +108,7 @@ public boolean mouseClicked(int mouseX, int mouseY, int button) {
108108
((SlotWidget) children.get(0)).getHandle().getStack().getDisplayName() +
109109
": " + posString));
110110
return false;
111-
} catch (Throwable e) {
111+
} catch (NumberFormatException e) {
112112
GTLog.logger.error("Could not reflect GregTech WidgetLabel text", e);
113113
}
114114
}

src/main/java/gregtech/common/items/EnchantmentTableTweaks.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ private static void onContainerOpen(Container container) {
5353
resultSlot.slotNumber = previousLapisSlot.slotNumber;
5454
container.inventorySlots.set(index, resultSlot);
5555
}
56-
} catch (Throwable exception) {
56+
} catch (RuntimeException exception) {
5757
GTLog.logger.warn("Failed to replace enchantment container slot", exception);
5858
}
5959
}

src/main/java/gregtech/common/worldgen/LootTableHelper.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -55,9 +55,9 @@ public static void initialize() {
5555
gsonField.setAccessible(true);
5656
Gson gsonInstance = (Gson) gsonField.get(null);
5757
replaceGsonTypeHierarchySerializer(gsonInstance, LootEntry.class, LootTableEntrySerializerDelegate::new);
58-
} catch (Throwable exception) {
59-
GTLog.logger.fatal("Failed to initialize loot table helper", exception);
60-
throw new RuntimeException(exception);
58+
} catch (SecurityException | IllegalAccessException e) {
59+
GTLog.logger.fatal("Failed to initialize loot table helper", e);
60+
throw new IllegalStateException(e);
6161
}
6262
registerLootEntry("gregtech:meta_item", LootEntryMetaItem::deserialize);
6363
registerLootEntry("gregtech:ore_dict", LootEntryOreDict::deserialize);

0 commit comments

Comments
 (0)