uncaught exception handler thing

it also exists in java yes
This commit is contained in:
Chayapak 2023-08-09 18:52:57 +07:00
parent 7c1063daa3
commit 92dffdc2ed

View file

@ -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;