[Unsolved] Catching Exceptions when Loading Another Plugin

Discussion in 'Plugin Development' started by meguy26, Apr 14, 2015.

Thread Status:
Not open for further replies.
  1. Offline

    meguy26

    So im creating a simple plugin that tests other plugins, and ive come across an issue, my plugin is designed to reload all other plugins and generate a crash report if they throw an exception:
    Code:
                                for(int i = 0; i < plugs.length; i++){
                                    Plugin p = plugs[i];
                                    if(!p.getName().equals("EasyTest")){
                                        try {
                                            man.enablePlugin(p);
                                            plugins.add(p.getName());
                                        } catch (Exception e){
                                            String timestamp = new SimpleDateFormat("dd:MM:yyyy-HH:mm:ss").format(new Date());
                                            log.severe("An exception occured while enabling " + p.getName() + " generating a crash report and saving to EasyTest//crashes//" + p.getName() + "//" + timestamp);
                                            new CrashGeneratorTask(call.getDataFolder().getAbsolutePath() + "\\crashes\\" + p.getName() + "\\" + timestamp + ".txt" , p, e, plugins, "enabling", timestamp, false).runTaskLaterAsynchronously(call, 20);
                                        }
                                    }
                                }
    However, man.disablePlugin(p); seems to catch and print its own stack traces, is there a way i can catch the stack traces, or am i hopelessly blocked?

    Also, please do not yell at me for catchin "Exception" im in testing and that will change!
     
  2. Offline

    mine-care

    Code:
    public void disablePlugin(Plugin plugin)
           {
             if (plugin.isEnabled())
             {
               try
               {
                 plugin.getPluginLoader().disablePlugin(plugin);
               }
               catch (Throwable ex)
               {
                 this.server.getLogger().log(Level.SEVERE, "Error occurred (in the plugin loader) while disabling " + plugin.getDescription().getFullName() + " (Is it up to date?)", ex);
               }
               try
               {
                 this.server.getScheduler().cancelTasks(plugin);
               }
               catch (Throwable ex)
               {
                 this.server.getLogger().log(Level.SEVERE, "Error occurred (in the plugin loader) while cancelling tasks for " + plugin.getDescription().getFullName() + " (Is it up to date?)", ex);
               }
               try
               {
                 this.server.getServicesManager().unregisterAll(plugin);
               }
               catch (Throwable ex)
               {
                 this.server.getLogger().log(Level.SEVERE, "Error occurred (in the plugin loader) while unregistering services for " + plugin.getDescription().getFullName() + " (Is it up to date?)", ex);
               }
               try
               {
                 HandlerList.unregisterAll(plugin);
               }
               catch (Throwable ex)
               {
                 this.server.getLogger().log(Level.SEVERE, "Error occurred (in the plugin loader) while unregistering events for " + plugin.getDescription().getFullName() + " (Is it up to date?)", ex);
               }
               try
               {
                 this.server.getMessenger().unregisterIncomingPluginChannel(plugin);
                 this.server.getMessenger().unregisterOutgoingPluginChannel(plugin);
               }
               catch (Throwable ex)
               {
                 this.server.getLogger().log(Level.SEVERE, "Error occurred (in the plugin loader) while unregistering plugin channels for " + plugin.getDescription().getFullName() + " (Is it up to date?)", ex);
               }
             }
           }
    This piece of code is in the class "SimplePluginManager", Thats how it looks like. You can figure how to use it yourself and mabe build an alternative method that unloads plugins :- )
     
  3. Offline

    meguy26

    @mine-care
    lemme see what i can do

    EDIT:
    @mine-care
    what about the enable method?

    Apparently, this is not possible, at least for me. With a whole bunch of reflection and hacky stuff I do not know how to do, catching an exception would be possible, but I guess my project has to be scrapped. :(

    EDIT by Timtower: merged posts
     
    Last edited by a moderator: Apr 15, 2015
  4. Offline

    nverdier

    @meguy26 So are you... Still looking for this to be solved?
     
  5. Offline

    meguy26

    @nverdier
    No, but i do not know how to get it locked, i guess i should just do:

    @mrCookieSlime
    Please lock this thread.
     
  6. Offline

    mrCookieSlime

    Locked on request.

    @meguy26
    Please use the Report button for lock requests instead.
     
Thread Status:
Not open for further replies.

Share This Page