0

In code

int x = 0;
int y = 1 / x;

Exception in thread "main" java.lang.ArithmeticException: / by zero
    at sample.MyClass.main(MyClass.java:16)

How I can get somebody like

Exception in thread "main" java.lang.ArithmeticException: / by zero
    at sample.MyClass.main(MyClass.java:16,12)[/code]
ivan_pozdeev
  • 33,874
  • 19
  • 107
  • 152
Iaroslav Baranov
  • 1,100
  • 9
  • 17

2 Answers2

2

You can't. When you print the exception it contains the StackTraceElement

This is the responsible method for above result

 public StackTraceElement(String declaringClass, String methodName,
                             String fileName, int lineNumber) {
  this.declaringClass = Objects.requireNonNull(declaringClass, "Declaring class is null");
  this.methodName     = Objects.requireNonNull(methodName, "Method name is null");
  this.fileName       = fileName;
  this.lineNumber     = lineNumber;
 }

Here there is no way to set column number.

Also StackTraceElement is a final class. you can't extend it and override either.

Ruchira Gayan Ranaweera
  • 34,993
  • 17
  • 75
  • 115
0

It's not possible. If you want to get a more precised line number, use extra carriage returns like in this example :

yourObject.
    aMethod().
         anotherMethod().
             aLastMethod();
ToYonos
  • 16,469
  • 2
  • 54
  • 70