e.printStackTrace()
と
System.out.println(e)
と
System.out.println(e.getMessage())
の違い。
public class App {
public static void main(String[] args) throws Exception {
String aaa = "aaa";
try{
aaa.substring(1000);
}catch(Exception e){
e.printStackTrace();
System.out.println(e);
System.out.println(e.getMessage());
}
}
}
e.printStackTrace()の場合
java.lang.StringIndexOutOfBoundsException: begin 1000, end 3, length 3
at java.base/java.lang.String.checkBoundsBeginEnd(String.java:4604)
at java.base/java.lang.String.substring(String.java:2707)
at java.base/java.lang.String.substring(String.java:2680)
at App.main(App.java:8)
System.out.println(e)の場合
java.lang.StringIndexOutOfBoundsException: begin 1000, end 3, length 3
※System.out.println(e.fillInStackTrace())も同じ結果になる。
System.out.println(e.getMessage())の場合
begin 1000, end 3, length 3