이 페이지는 아직 영어로 제공되지 않습니다. 번역 작업 중입니다.
현재 번역 프로젝트에 대한 질문이나 피드백이 있으신 경우 언제든지 연락주시기 바랍니다.

Metadata

ID: java-best-practices/preserve-stack-trace

Language: Java

Severity: Notice

Category: Best Practices

Description

This rule identifies when exceptions are raised within a catch block but are not relevant to the exception parameter specified in the catch block. This can result in the original exception’s stack trace information being lost, which leads to throwing less detailed exceptions.

Non-Compliant Code Examples

public class Foo {
    void foo() {
        try {
            Integer.parseInt("foo");
        } catch (Exception e) {
            throw new Exception(e.getMessage()); // only throwing the message here
        }
    }
}

Compliant Code Examples

public class Foo {
    void foo() {
        try {
            Integer.parseInt("foo");
        } catch (Exception e) {
            throw new Exception(e); // sending the full exception at least
        }
    }
}
PREVIEWING: dgreen15/github-error-fix