gpt4 book ai didi

java - 除了异常堆栈跟踪中的行号之外,还包括源列号

转载 作者:行者123 更新时间:2023-12-02 05:21:25 25 4
gpt4 key购买 nike

在代码中

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

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

如何才能找到像我这样的人

Exception in thread "main" java.lang.ArithmeticException: / by zero
at sample.MyClass.main(MyClass.java:16,12)[/code]

最佳答案

你不能。当您打印异常时,它包含 StackTraceElement

这是导致上述结果的方法

 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;
}

此处无法设置列数。

此外,StackTraceElement 是一个final 类。您也无法扩展它并覆盖

关于java - 除了异常堆栈跟踪中的行号之外,还包括源列号,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26480342/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com