How to get the line number in error in java? -


I know the line in the error to_rate = search (list, wrong); How can I get the line number of this line when NullPointerException is the type of error? Or in line number in general?

I tried some things, the closest it is to a called.getLineNumber () which gives me the line number of the called StackTraceElement call = new throttle (). FillInStackTrace (). GetStackTrace () [0];

  public test object [] myfind (subtitle list) throws an exception {test object] to_return = null; Try {to_return = find (list, wrong); } Hold (formerly rationalist expansion) {// logstore exposition (ex); StackTraceElement = new throttle () FillInStackTrace (). GetStackTrace () [0]; StackTrace element calling = new throttle (). FillInStackTrace (). GetStackTrace () [1]; New exception throw (this.add_debugging_info (Called, Calling, Ex .getMessage ())); } Hold (NullPointerException npe) {StackTraceElement Called = New Throwable (). FillInStackTrace (). GetStackTrace () [0]; StackTrace element calling = new throttle (). FillInStackTrace (). GetStackTrace () [1]; LogStoreException (NPE); System.out.println ("Line Number:" + npe.getStackTrace () [0] .getLineNumber ()); System.out.println ("line number 2:" + integer. Stosting (called .gat linenumber ()); System.out.println (this.add_debugging_info (Called, Calling, N.G.Get Message)); New exception throw (this.add_debugging_info (calling, calling, npate message ()); } Catch (Exception Pre) {StackTraceElement Called = New Throwable (). FillInStackTrace (). GetStackTrace () [0]; StackTrace element calling = new throttle (). FillInStackTrace (). GetStackTrace () [1]; New exception throw (this.add_debugging_info (Called, Calling, Ex .getMessage ())); } Finally {// Unregistered All (); // (to) unregistered; Return to_return; }}    

  1. If you want the current stack trace, If you want to force the JVM to fill the stack trace, please -XX: -AmstastatressInstatro on your JVM

Comments