Hello again, I am trying to create an error uploader plugin that uploads whatever the occurred error was of whatever plugin to hastebin.com by its API. And I think the UncaughtExceptionHandler thing that was in the Java JDK could "listen to" and "report" any errors on any thread. This is what I have right now, but I wonder if Spigot has a specific thread I need to put in. Code (Text): Thread myThread = new Thread(//What should I put here?); myThread.setUncaughtExceptionHandler(new Thread.UncaughtExceptionHandler() { public void uncaughtException(Thread myThread, Throwable e) { System.out.println(myThread.getName() + " throws exception: " + e); } }); Any question related replies are highly appreciated . Thank you
You could use Code (Text): System.out.println(Thread.currentThread().getName()); System.out.println(Thread.currentThread().getId()); To try and figure out what the main thread's called. EDIT: I did some research and it looks like you should use: Code (Text): Thread.setDefaultUncaughtExceptionHandler(handler);
Half the time, if not all the time, these exceptions won't reach your UncaughtExceptionHandler. They are handled in their specific try-catch blocks, and passed to the logger. However, you should be able to attach a filter to that Logger which checks if it's reporting an exception, and cancel the logging there (or replace the message with a String) and handle the exception yourself.
Sorry but I couldn't understand what do you mean by attach a filter to that Logger. Do you mean this filter? (https://docs.oracle.com/javase/7/docs/api/java/util/logging/Filter.html) And this Logger? (http://docs.oracle.com/javase/7/docs/api/java/util/logging/Logger.html?is-external=true) If so, how would I use them together? Sorry for asking too much, I am kinda a noob at this xP
Thank you for researching for me , but what should the "handler" in Thread.setDefaultUncaughtExceptionHandler(handler) be?
An uncaught exception handler like the one you made in your first post, however you should ignore what I said and try to do what DarkSeraphim said. I don't use the Logger a whole lot so I can't help you there.
1. Create a new LogHandler 2. Call the attach method 3. Handle the console output & filter the input for keywords like "exception" etc. (see example below) 4. Upload your stuff to hastebin Code (Text): import java.util.logging.Handler; import java.util.logging.LogRecord; import org.bukkit.Bukkit; public class LogHandler extends Handler{ public void attachToBukkit(){ Bukkit.getLogger().addHandler(this); } @Override public void close() throws SecurityException { } @Override public void flush() { } @Override public void publish(LogRecord arg0) { if(arg0.getMessage().contains("Exception")){ //upload dis } } }
Thank you, but what should I put in publish(//here?) The problem is that I don't know how to handle the console output... is it like getLogger().getSomething() but I can't find the relevant method.
This LogHandler gets the output of every single line. So when you got a random exception...: net.java.RandomCrappyException: You did something wrong at bla1 at bla2 at bla3 ...Every line gets passed to you as a LogRecord in the publish function. Then you simply got to put all of them together (Just add them all in a String) and then upload this String to pastebin using the jPastebin library: https://github.com/BrianBB/jPastebin