Improve exception handling
All checks were successful
continuous-integration/drone/push Build is passing

This commit is contained in:
Bea 2023-01-15 05:00:44 +01:00
parent d2abeb35fc
commit ee4c5155fa
3 changed files with 15 additions and 3 deletions

View File

@ -77,7 +77,12 @@ public class HidekoBot
);
jda = jdaBuilder.build().awaitReady();
} catch (Exception e)
} catch (InterruptedException e) {
LOGGER.error(e.getMessage()); // print the error message, omit the stack trace.
Thread.currentThread().interrupt(); // send interrupt to the thread.
shutdown(); // if we failed connecting and authenticating, then quit.
}
catch (Exception e)
{
LOGGER.error(e.getMessage()); // print the error message, omit the stack trace.
shutdown(); // if we failed connecting and authenticating, then quit.

View File

@ -67,7 +67,7 @@ public class Trivia
List<TriviaCategory> categories = Trivia.parseCategories(categoriesJson);
if(categories.isEmpty())
return new MessageResponse("Error parsing trivia categories!", null); // todo nicer with emojis
categories.sort(new TriviaCategoryComparator());
EmbedBuilder embedBuilder = new EmbedBuilder();

View File

@ -47,7 +47,14 @@ public class ConfigurationSource
if(!fsConfigFile.exists())
{
// try to create config file
try { fsConfigFile.createNewFile(); }
try {
if(!fsConfigFile.createNewFile())
{
LOGGER.error("We tried creating a file that already exists!");
HidekoBot.shutdown();
return;
}
}
catch (IOException e) {
LOGGER.error("Error creating configuration file!", e);
HidekoBot.shutdown();