1.17.1 Catching all errors in plugin

Discussion in 'Spigot Plugin Development' started by Snicko, Sep 9, 2021.

  1. I have a very large plugin I use for my server, and I've just implemented an error logger which catches errors and sends the stack trace to my Discord; so I am notified when there are errors and I have an easy to read log; and it also sends the player a message if applicable.

    The problem with this is
    1) I have to add try/catch on all my methods
    2) It doesn't pick up async methods (eg. calling an async method in the try/catch)

    I'm assuming there's no way around this other than adding the try/catch to every method I want to check and inside the async methods?

    Otherwise has anyone got any other suggestions?
     
  2. You might be easier off with implementing a logging handler and only considering the error messages coming from your plugin. Filtering for your plugin though would likely boil down to analyzing the log message and seeing if your plugin was mentioned ("Couldn't pass event X to plugin Y"). I don't think there's another option unfortunately if you don't want to wrap your own code in some way. If you don't, exceptions will travel up until they're caught, which is usually inside the plugin manager or scheduler and they don't really give any entry-point to handling these exceptions.
     
    • Informative Informative x 1