Solved Catch all exceptions?

Discussion in 'Plugin Development' started by godlypowerr, Mar 18, 2017.

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

    godlypowerr

    Hi,
    I'd love to be able to catch all the exceptions thrown by my plugin, without having to do an extensive amount of try/catch's everywhere. Usually to do such a thing you'd do something like this:

    Code:
    public static void main( String[] args ){
      try{
        //main code
      } catch (Exception e){
        //do exception handling
      }
    }
    However, since I don't have access to the main class, is it possible to do anywhere else? I couldn't find an exception handler class or method in the bukkit javadocs, but maybe I'm looking in the wrong places.
     
  2. Offline

    timtower Administrator Administrator Moderator

    @godlypowerr Bukkit is catching exceptions already.
    It is actually your job to prevent them from happening all together.
     
  3. Offline

    Irantwomiles

    Try catch does nothing other than give you a different message about your error. You shouldn't be expecting errors...
     
  4. Offline

    godlypowerr

    @timtower
    I am aware of that. I'm trying to get error reports sent to my email instead of being logged. Some Java plugins/software have the ability to change the exception handler. In the case of Bukkit, as you stated, they're already being caught and logged. I'd like to redirect the exception output.
     
  5. Offline

    Zombie_Striker

    @godlypowerr
    Use this to convert your error message into a string:
    Code:
    StringWriter sw =newStringWriter();
    PrintWriter pw =newPrintWriter(sw);
    e.printStackTrace(pw);
    sw.toString();// stack trace as a string
    
    Also, don't prevent it from being logged. If a server owner does not know that there is a problem with your plugin, then they will not know they need to update/fix it
     
  6. Offline

    timtower Administrator Administrator Moderator

    @godlypowerr Will probably send a lot of issues in a small time window.
    Test and make sure they don't happen.
     
  7. Offline

    godlypowerr

    @Zombie_Striker @timtower
    Thanks guys! Not exactly what I was looking for, but I suppose there is no functionality for what I want exactly.
     
Thread Status:
Not open for further replies.

Share This Page