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.
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.
Well you normally just have to look at the stack trace and this will tell you where it is thrown. Here's an example:
This will print out something like the following when an error is thrown:Code:try {
// The below throws an exception
MyClass.doSomething();
} catch (Exception e) {
System.err.println("Error: "+ e.getMessage());
e.printStackTrace();
}
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.Code:Error: null
java.lang.NullPointerException
at com.myPackage.test.java:25)
at com.myPackage.test.java:18)
at com.myPackage.test.java:14)
All times are GMT -7. The time now is 02:35 AM. |