Uploaded image for project: 'JDK'
  1. JDK
  2. JDK-4086065

rfe: Method.invoke() is difficult to debug

XMLWordPrintable

    • Icon: Enhancement Enhancement
    • Resolution: Duplicate
    • Icon: P5 P5
    • None
    • 1.1.3
    • core-libs
    • x86
    • windows_95



      Name: joT67522 Date: 10/14/97


      import java.lang.reflect.Method;

      /**
       * Test ease of debugging exceptions in deep invocations.
       * Invocation is useful in loosely coupled systems where
       * method calls are parameter driven services.
       *
       * Note that in the exception stack trace there is no
       * mention of where the initial exception occured. This
       * makes it very hard to debug deep invocations, as one
       * must resort to embedding print() to isolate the bug.
       *
       * SUGGESTION:
       * Since the Method must be created before invoke(), the
       * greatest exception risk is already past when invoke()
       * is called. One solution would be to add:
       * Method.invokeNoCatch(Object obj, Object args[])
       * which throws no exceptions but does throw errors.
       *
       * @author Jack Harich - 8/30/97 - ###@###.###
       */
      public class TestInvoke {

      //---------- Private Fields ------------------------------
      // (none)

      //---------- Initialization ------------------------------
      public static void main(String args[]) {
          new TestInvoke();
      }
      public TestInvoke() {
          try {
              // Create method
              Class[] classes = { }; // No arg
              Method method = this.getClass().getMethod("logonRequested", classes);

              // Call method
              Object[] args = { }; // No arg
              method.invoke(this, args);

          } catch(Exception ex) {
              print("TestInvoke exception");
              ex.printStackTrace();
          }
      }
      //---------- Public Methods ------------------------------
      public void logonRequested() {
          print("TestInvoke.logonRequested() - entered");
          // Create test exception
          int divisor = 0;
          int test = 5 / divisor; // <-----<<< EXCEPTION
      }
      //---------- Private Methods -----------------------------
      //--- Std
      private static void print(String text) {
          System.out.println(text);
      }

      } // End class
      company - Consultant , email - ###@###.###
      ======================================================================

            apalanissunw Anand Palaniswamy (Inactive)
            johsunw Joon Oh (Inactive)
            Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

              Created:
              Updated:
              Resolved:
              Imported:
              Indexed: