Solved Unhandled Exception Warning (IntelliJ)

Discussion in 'Spigot Plugin Development' started by KZ5EE, Jun 3, 2017.

  1. Greetings!

    I'm following the guide for creating plugins under "Using Multiple Config Files": https://www.spigotmc.org/wiki/config-files/#using-multiple-configuration-files

    In my IDE (IntelliJ), I get the red squiggly lines under
    Code (Text):
    config.load(configf);
    special.load(specialf);
    When I mouse over, it says: "Unhandled Exeption: org.bukkit.configuration.InvalidConfigurationException"

    I copied the code as it is in the example and still get the error. Is there a setting I need to change within the IDE to make this work?
     
  2. Mas

    Mas

    Exceptions basically mean that the method you are trying to use could result in an error, and it's up to you to handle what happens in the case of an exception being thrown.
    This is something you should really learn before using Java APIs, as it is quite basic stuff.
    This should help you understand: https://docs.oracle.com/javase/tutorial/essential/exceptions/
     
  3. Make a try/catch around the lines or in the whole method with InvalidConfigurationException in the catch.
     
  4. I'm not sure if you are starting to go blind but in the tutorial he says himself to do a try catch around it, seems like you need to learn more java before doing this project or re read the tutorial.
     
  5. I copied it as it is in the example:

    Code (Text):
        private void createFiles() {

            configf = new File(getDataFolder(), "config.yml");
            specialf = new File(getDataFolder(), "special.yml");

            if (!configf.exists()) {
                configf.getParentFile().mkdirs();
                saveResource("config.yml", false);
            }
            if (!specialf.exists()) {
                specialf.getParentFile().mkdirs();
                saveResource("special.yml", false);
            }

            config = new YamlConfiguration();
            special = new YamlConfiguration();
            try {
                config.load(configf);
                special.load(specialf);
            } catch (IOException e) {
                e.printStackTrace();
            }
        }
    That's why I'm scratching my head with it. There's a try...catch around those lines.
     
  6. The try/catch isn't catching InvalidConfigurationException, only IOException.
    Change it to:
    Code (Text):
    try {
                config.load(configf);
                special.load(specialf);
            } catch (IOException | InvalidConfigurationException e) {
                e.printStackTrace();
            }
    or
    Code (Text):
    try {
                config.load(configf);
                special.load(specialf);
            } catch (Exception e) {
                e.printStackTrace();
            }
     
    • Winner Winner x 2
  7. No need to be so r00d fam.
     
    • Agree Agree x 1
  8. Changing IOException to Exception solved it. I'm still getting used to the whole OO paradigm.