Skip to content

Commit 6fdaf80

Browse files
Rename "uncaught exception handler" to "exception handler"
1 parent 7e85921 commit 6fdaf80

File tree

11 files changed

+26
-29
lines changed

11 files changed

+26
-29
lines changed

invui/src/main/java/xyz/xenondevs/invui/InvUI.java

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ public final class InvUI implements Listener {
2121

2222
private final List<Runnable> disableHandlers = new ArrayList<>();
2323
private @Nullable Plugin plugin;
24-
private BiConsumer<? super String, ? super Throwable> uncaughtExceptionHandler = (msg, e) -> getPlugin().getComponentLogger().error(msg, e);
24+
private BiConsumer<? super String, ? super Throwable> exceptionHandler = (msg, e) -> getPlugin().getComponentLogger().error(msg, e);
2525

2626
private InvUI() {}
2727

@@ -87,23 +87,24 @@ public void setPlugin(@Nullable Plugin plugin) {
8787
}
8888

8989
/**
90-
* Sets a handler for uncaught exceptions in InvUI.
90+
* Sets a handler for exceptions that were thrown in user-provided code but suppressed by InvUI,
91+
* such as when handling inventory events or similar.
9192
*
92-
* @param uncaughtExceptionHandler The new uncaught exception handler.
93+
* @param exceptionHandler The new exception handler.
9394
*/
94-
public void setUncaughtExceptionHandler(BiConsumer<? super String, ? super Throwable> uncaughtExceptionHandler) {
95-
this.uncaughtExceptionHandler = uncaughtExceptionHandler;
95+
public void setExceptionHandler(BiConsumer<? super String, ? super Throwable> exceptionHandler) {
96+
this.exceptionHandler = exceptionHandler;
9697
}
9798

9899
/**
99-
* Handles an uncaught exception using the configured
100-
* {@link #setUncaughtExceptionHandler(BiConsumer) uncaught exception handler}.
100+
* Handles an exception using the configured
101+
* {@link #setExceptionHandler(BiConsumer) exception handler}.
101102
*
102103
* @param msg An additional message that provides more context.
103-
* @param t The uncaught exception that was thrown.
104+
* @param t The exception that was thrown.
104105
*/
105-
public void handleUncaughtException(String msg, Throwable t) {
106-
uncaughtExceptionHandler.accept(msg, t);
106+
public void handleException(String msg, Throwable t) {
107+
exceptionHandler.accept(msg, t);
107108
}
108109

109110
/**

invui/src/main/java/xyz/xenondevs/invui/gui/SlotElement.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ record Item(xyz.xenondevs.invui.item.Item item) implements SlotElement {
6565
try {
6666
return item.getItemProvider(player).get(Languages.getInstance().getLocale(player));
6767
} catch (Throwable t) {
68-
InvUI.getInstance().handleUncaughtException("Failed to get item stack for item slot element", t);
68+
InvUI.getInstance().handleException("Failed to get item stack for item slot element", t);
6969
}
7070

7171
return null;

invui/src/main/java/xyz/xenondevs/invui/internal/menu/CustomContainerMenu.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -605,7 +605,7 @@ protected void runInInteractionContext(Runnable run) {
605605
interactionContext.set(true);
606606
run.run();
607607
} catch (Throwable t) {
608-
InvUI.getInstance().handleUncaughtException("An exception occurred while handling a window interaction", t);
608+
InvUI.getInstance().handleException("An exception occurred while handling a window interaction", t);
609609
} finally {
610610
interactionContext.set(false);
611611
}

invui/src/main/java/xyz/xenondevs/invui/internal/util/CollectionUtils.java

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@
99
import java.util.List;
1010
import java.util.function.Consumer;
1111
import java.util.function.Function;
12-
import java.util.logging.Level;
1312

1413
public class CollectionUtils {
1514

@@ -43,7 +42,7 @@ public static <T> void forEachCatching(Iterable<? extends T> iterable, Consumer<
4342
action.accept(obj);
4443
i++;
4544
} catch (Throwable t) {
46-
InvUI.getInstance().handleUncaughtException(message + " (" + i + ")", t);
45+
InvUI.getInstance().handleException(message + " (" + i + ")", t);
4746
}
4847
}
4948
}

invui/src/main/java/xyz/xenondevs/invui/internal/util/FuncUtils.java

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@
55
import xyz.xenondevs.invui.InvUI;
66

77
import java.util.function.Supplier;
8-
import java.util.logging.Level;
98

109
public class FuncUtils {
1110

@@ -23,7 +22,7 @@ public static <T> T getSafely(@NonNull Supplier<? extends T> supplier, T fallbac
2322
try {
2423
return supplier.get();
2524
} catch (Throwable t) {
26-
InvUI.getInstance().handleUncaughtException("Failed to get value from supplier", t);
25+
InvUI.getInstance().handleException("Failed to get value from supplier", t);
2726
return fallback;
2827
}
2928
}

invui/src/main/java/xyz/xenondevs/invui/inventory/CompositeInventory.java

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@
1111
import xyz.xenondevs.invui.inventory.event.UpdateReason;
1212

1313
import java.util.Collection;
14-
import java.util.logging.Level;
1514

1615
/**
1716
* An {@link Inventory} which is composed of multiple other {@link Inventory Inventories}.
@@ -195,7 +194,7 @@ public boolean callClickEvent(int slot, Click click) {
195194
try {
196195
handler.accept(clickEvent);
197196
} catch (Throwable t) {
198-
InvUI.getInstance().handleUncaughtException("An exception occurred while handling an inventory event", t);
197+
InvUI.getInstance().handleException("An exception occurred while handling an inventory event", t);
199198
}
200199
}
201200

@@ -216,7 +215,7 @@ public ItemPreUpdateEvent callPreUpdateEvent(@Nullable UpdateReason updateReason
216215
try {
217216
handler.accept(event);
218217
} catch (Throwable t) {
219-
InvUI.getInstance().handleUncaughtException("An exception occurred while handling an inventory event", t);
218+
InvUI.getInstance().handleException("An exception occurred while handling an inventory event", t);
220219
}
221220
}
222221

invui/src/main/java/xyz/xenondevs/invui/inventory/Inventory.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -464,7 +464,7 @@ public boolean callClickEvent(int slot, Click click) {
464464
try {
465465
handler.accept(clickEvent);
466466
} catch (Throwable t) {
467-
InvUI.getInstance().handleUncaughtException("An exception occurred while handling an inventory event", t);
467+
InvUI.getInstance().handleException("An exception occurred while handling an inventory event", t);
468468
}
469469
}
470470

@@ -491,7 +491,7 @@ public ItemPreUpdateEvent callPreUpdateEvent(@Nullable UpdateReason updateReason
491491
try {
492492
handler.accept(event);
493493
} catch (Throwable t) {
494-
InvUI.getInstance().handleUncaughtException("An exception occurred while handling an inventory event", t);
494+
InvUI.getInstance().handleException("An exception occurred while handling an inventory event", t);
495495
}
496496
}
497497
return event;
@@ -516,7 +516,7 @@ public void callPostUpdateEvent(@Nullable UpdateReason updateReason, int slot, @
516516
try {
517517
handler.accept(event);
518518
} catch (Throwable t) {
519-
InvUI.getInstance().handleUncaughtException("An exception occurred while handling an inventory event", t);
519+
InvUI.getInstance().handleException("An exception occurred while handling an inventory event", t);
520520
}
521521
}
522522
}

invui/src/main/java/xyz/xenondevs/invui/inventory/ObscuredInventory.java

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,6 @@
1313
import java.util.EnumSet;
1414
import java.util.Set;
1515
import java.util.function.IntPredicate;
16-
import java.util.logging.Level;
1716
import java.util.stream.IntStream;
1817

1918
/**
@@ -160,7 +159,7 @@ public boolean callClickEvent(int slot, Click click) {
160159
try {
161160
handler.accept(clickEvent);
162161
} catch (Throwable t) {
163-
InvUI.getInstance().handleUncaughtException("An exception occurred while handling an inventory event", t);
162+
InvUI.getInstance().handleException("An exception occurred while handling an inventory event", t);
164163
}
165164
}
166165

@@ -180,7 +179,7 @@ public ItemPreUpdateEvent callPreUpdateEvent(@Nullable UpdateReason updateReason
180179
try {
181180
handler.accept(event);
182181
} catch (Throwable t) {
183-
InvUI.getInstance().handleUncaughtException("An exception occurred while handling an inventory event", t);
182+
InvUI.getInstance().handleException("An exception occurred while handling an inventory event", t);
184183
}
185184
}
186185

invui/src/main/java/xyz/xenondevs/invui/inventory/VirtualInventoryManager.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -155,7 +155,7 @@ private void deserializeAll() {
155155
VirtualInventory inventory = VirtualInventory.deserialize(in);
156156
inventories.put(inventory.getUuid(), inventory);
157157
} catch (IOException e) {
158-
InvUI.getInstance().handleUncaughtException(
158+
InvUI.getInstance().handleException(
159159
"Failed to deserialize a VirtualInventory from file " + file.getPath(),
160160
e
161161
);
@@ -174,7 +174,7 @@ private void serializeAll() {
174174
try (FileOutputStream out = new FileOutputStream(file)) {
175175
inventory.serialize(out);
176176
} catch (IOException e) {
177-
InvUI.getInstance().handleUncaughtException(
177+
InvUI.getInstance().handleException(
178178
"Failed to serialize a VirtualInventory to file " + file.getPath(),
179179
e
180180
);

invui/src/test/java/xyz/xenondevs/invui/inventory/CompositeInventoryTest.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ public class CompositeInventoryTest {
2525
@BeforeAll
2626
public static void setUp() {
2727
server = MockBukkit.mock();
28-
InvUI.getInstance().setUncaughtExceptionHandler((msg, t) -> {
28+
InvUI.getInstance().setExceptionHandler((msg, t) -> {
2929
throw new AssertionError(msg, t);
3030
});
3131
}

0 commit comments

Comments
 (0)