From 92dffdc2ed694102c5c521592a0472e911e06d98 Mon Sep 17 00:00:00 2001 From: ChomeNS <95471003+ChomeNS@users.noreply.github.com> Date: Wed, 9 Aug 2023 18:52:57 +0700 Subject: [PATCH] uncaught exception handler thing it also exists in java yes --- .../land/chipmunk/chayapak/chomens_bot/Main.java | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/src/main/java/land/chipmunk/chayapak/chomens_bot/Main.java b/src/main/java/land/chipmunk/chayapak/chomens_bot/Main.java index c41f81b..cad96fc 100644 --- a/src/main/java/land/chipmunk/chayapak/chomens_bot/Main.java +++ b/src/main/java/land/chipmunk/chayapak/chomens_bot/Main.java @@ -2,6 +2,7 @@ package land.chipmunk.chayapak.chomens_bot; import com.google.common.util.concurrent.ThreadFactoryBuilder; import land.chipmunk.chayapak.chomens_bot.plugins.ConsolePlugin; +import land.chipmunk.chayapak.chomens_bot.util.ExceptionUtilities; import land.chipmunk.chayapak.chomens_bot.util.HttpUtilities; import land.chipmunk.chayapak.chomens_bot.util.LoggerUtilities; import net.dv8tion.jda.api.JDA; @@ -82,6 +83,19 @@ public class Main { } }, 0, 1, TimeUnit.MINUTES); + Thread.currentThread().setUncaughtExceptionHandler((thread, throwable) -> { + LoggerUtilities.error( + String.format( + "Caught an uncaught exception in thread %s!\n%s", + + thread.getName(), + ExceptionUtilities.getStacktrace(throwable) + ) + ); + + if (throwable instanceof OutOfMemoryError) System.exit(1); + }); + if (!config.backup.enabled) { initializeBots(); return;