Hello, I am trying to figure out how to catch any exceptions that are thrown and get details about them. Is there a way to accomplish this without building a catch statement around all of my code?
Well, you can catch any uncaught exception in a certain thread by using thread.setDefaultExceptionHandler…
Exceptions thrown by your own code?
If that is the case then it wouldn’t be a “best practice” to do. An exception should only be thrown when the plugin can’t continue to end its work.
Why do want to do it?
If one was ever thrown, it would help to provide better error reporting, as you could send the console information about versions and log it to a file.
Once Ore is finished Sponge could implement sending crash reports to the Ore developer console like Google Play Store.
As Minecraft mostly is single threaded Thread.setDefaultUncaughtExceptionHandler
would catch also Sponge exceptions and exceptions of other plugins.
Edit: With setDefaultUncaughtExceptionHandler
uncaught exceptions of all threads will be caught. I really can’t decide whether it would be a good thing that is done by a plugin.
Alright, thank you for helping to explain this. I’ll just stick with the normal error reporting for now.
@zml has proposed an error reporting API that might be what you’re after
https://github.com/SpongePowered/SpongeAPI/pull/793
That looks perfect! Thanks for letting me know about it.