Source Code : Getting the Stack Trace of an Exception

Java Is Open Source Programming Language You Can Download From Java and Java Libraries From http://www.oracle.com. Click Here to download
We provide this code related to title for you to solve your developing problem easily. Libraries which is import in this program you can download from http://www.oracle.com. Click Here or search from google with Libraries Name you get jar file related it

Getting the Stack Trace of an Exception

          


public class Main {
  public static void main(String[] argv) throws Exception {

    try {
      int x = 1, y = 0;
      System.out.println(x / y);
    } catch (Throwable e) {
      StackTraceElement stack[] = e.getStackTrace();

      for (int i = 0; i < stack.length; i++) {
        String filename = stack[i].getFileName();
        if (filename == null) {
          System.out.println("filename is not available");
        }
        String className = stack[i].getClassName();
        System.out.println(className);
        String methodName = stack[i].getMethodName();
        System.out.println(methodName);
        boolean isNativeMethod = stack[i].isNativeMethod();
        System.out.println(isNativeMethod);
        int line = stack[i].getLineNumber();
        System.out.println(line);
      }
    }
  }
}

   
    
    
    
    
    
    
    
    
    
  

Thank with us