Ask Me Help Desk

Ask Me Help Desk (https://www.askmehelpdesk.com/forum.php)
-   Java (https://www.askmehelpdesk.com/forumdisplay.php?f=440)
-   -   Exceptions in java (https://www.askmehelpdesk.com/showthread.php?t=39137)

  • Oct 26, 2006, 02:08 AM
    kishorekumar
    Exceptions in java
    HI,
    I have a java class in which an exception occurred. Now the problem is I have to know from which class and from which method the exception is thrown.
  • Oct 30, 2006, 10:07 AM
    LTheobald
    Well you normally just have to look at the stack trace and this will tell you where it is thrown. Here's an example:

    Code:

    try {
      // The below throws an exception
      MyClass.doSomething();
    } catch (Exception e) {
      System.err.println("Error: "+ e.getMessage());
      e.printStackTrace();
    }

    This will print out something like the following when an error is thrown:
    Code:

    Error: null
    java.lang.NullPointerException
        at com.myPackage.test.java:25)
        at com.myPackage.test.java:18)
        at com.myPackage.test.java:14)

    The "at com.myPackage.test.java" part is the class that threw the error. The number following the colon is the line error the error was thrown on.

  • All times are GMT -7. The time now is 02:35 AM.