Solved How to catching errors?

Discussion in 'Plugin Help/Development/Requests' started by sooon_mitch, Apr 20, 2015.

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

    sooon_mitch

    I was reading up on how to catch errors coming from a Bukkit plugin but ran into many problems. First is, what methods are there to prevent the plugin from crashing in the first place if there is an error. Sorta like catching itself. Another is how can I get the stack traces from the errors from the plugin? Then log them with the same plugin? I really cant find a way to do this since the Bukkit server catches errors with custom code. So any help will be appreciated and also I am an experienced coder so please don't be shy on code talk.

    @nverdier Anyways. If I have this on multiple servers and have it in an alpha state I need it to collect every bug. Especially since I code in 4000+ lines of code on my usual plugins.

    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
     
    Last edited by a moderator: Jun 12, 2016
  2. Offline

    sooon_mitch

    @nverdier I have large plugins that I dont have time to test. I need the server to log errors so I can get the errors and debug them. That is my form of testing. Either way, if you know how to have the plugin collect its own exceptions that was not handled then I would like to know. If not then please stop commenting.
     
    Last edited: Apr 21, 2015
  3. Offline

    sooon_mitch

  4. Offline

    BizarrePlatinum

  5. Offline

    nverdier

    Bukkit will already catch errors and print out the stacktrace...
     
  6. Offline

    sooon_mitch

    @BizarrePlatinum Thank you for trying but I have tried that library and gotten errors from it. Also I don't think @nverdier is understanding what I am asking.
     
  7. Offline

    nverdier

    @sooon_mitch You want your plugin to catch any errors and print it out to the console?
     
  8. Offline

    sooon_mitch

    @nverdier No. I want to catch the stack trace and store it in my own file.
     
  9. Offline

    sooon_mitch

  10. Offline

    sooon_mitch

  11. Offline

    sooon_mitch

  12. Offline

    Msrules123

    This is what console debugging system was made for...
     
  13. Offline

    eyamaz

    @all Removed irrelevant posts. If you are not going to be constructive to a conversation, don't post.

    Edit: apparently "all" is actually a user...
     
    Totom3 likes this.
  14. Offline

    Totom3

    I'll start by saying that for the time it will take you to do one of the following solutions, you'd probably have fixed hundred of bugs. Debugging will save you a lot of time.

    As far as I understand, you want to print stack-traces and errors to a file, in the same format as they are in the console. Technically this is impossible, as stack-traces are printed exactly like any normal message. In reality, however, I can see a few ways of solving this:

    1. Preferred: intercepting log records marked with level = SEVERE. Will only work if you are using Loggers to print errors. Will not work if you are using ex.printStackTrace(). You will also need to know in advance which Loggers are used (probably yourPlugin.getLogger()). I said above that stack-traces are printed like normal messages, which is still true, but when using Loggers, you'd usually log them with a LogLevel of SEVERE or WARNING, in contrast of normal messages, etc... This allows you to differentiate them. So what you'll want to do is extend the Handler class and when a message is printed, you check whether the LogLevel is SEVERE or WARNING, in which case you also print the log to a file. Attach the handler to the Loggers you are using and enjoy. Note that this will not fix everything, as errors are not always logged as SEVERE or WARNING.

    2. You shouldn't do it but it could work: intercepting the messages printed and trying to parse a stack-trace. You could do that by attaching a custom Handler to the Loggers you are using.

    3. You really shouldn't do that but it could also work: same thing as #2 but instead of attaching a custom Handler to a Logger, you change System.out to a custom PrintWriter.

    I got to read @nverdier 's messages before they were deleted and I agree, you should debug instead of trying to catch errors.
     
    Last edited: May 1, 2015
  15. Offline

    sooon_mitch

    SOLVED
    @Totom3 Thank you, finally a legitimate answer!
     
  16. Offline

    Totom3

    Woops! I just noticed a big mistake in my answer: #2 was supposed to be "You shouldn't do it [...]". Edited the post above but wanted to make sure you see the change.

    No problem :p
     
Thread Status:
Not open for further replies.

Share This Page