
Throwable은 Exception과 Error를 모두 포함하는 추상 클래스입니다.
Throwable::getLine은 Throwable의 메소드가 맞습니다.
이 메소드는 Throwable에서 사용됩니다.
Throwable::getLine은 스택 트레이스에서 사용됩니다.
스택 트레이스에서 사용하는 예를 들어보겠습니다.
#hostingforum.kr
java
public class Main {
public static void main(String[] args) {
try {
method1();
} catch (Exception e) {
e.printStackTrace();
}
}
public static void method1() throws Exception {
try {
method2();
} catch (Exception e) {
throw e;
}
}
public static void method2() throws Exception {
throw new Exception("오류 발생");
}
}
위 예제에서 스택 트레이스에서 사용되는 예를 볼 수 있습니다.
Throwable::getLine은 deprecated된 경우는 없습니다.
이 메소드의 리턴 타입은 String[] 타입입니다.
이 메소드는 null을 리턴할 수 있습니다.
예를 들어, 다음과 같이 사용할 수 있습니다.
#hostingforum.kr
java
public class Main {
public static void main(String[] args) {
Throwable throwable = new Exception("오류 발생");
String[] lines = throwable.getStackTrace().getFileName();
for (String line : lines) {
System.out.println(line);
}
}
}
위 예제에서 getLine은 사용되지 않았지만 getStackTrace()를 사용하여 스택 트레이스에서 사용할 수 있습니다.
getLine은 deprecated된 메소드가 아니지만, getStackTrace()를 사용하는 것이 더 일반적입니다.
2025-07-26 02:08