getMessage()とprintStackTrace()の違い
ExecutorServiceを使用した場合に発生するExecutionExceptionのgetMessage()について
public class Outer {
public static void main(String[] args) throws InterruptedException {
SampleException se = new SampleException("xxxxxx");
System.out.println(se.getMessage());
method();
Exception ex = new Exception("eeee");
System.out.println(ex.getMessage());
Exception ex2 = new ExecutionException(se);
System.out.println(ex2.getMessage());
}
static void method() {
SampleException se = new SampleException("yyyy");
se.printStackTrace();
}
}
ExecutionExceptionのgetMessage()は、クラス名が前につく
xxxxxx
com.mycompany.mavenproject1.SampleException: yyyy
at com.mycompany.mavenproject1.Outer.method(Outer.java:37)
at com.mycompany.mavenproject1.Outer.main(Outer.java:30)
eeee
com.mycompany.mavenproject1.SampleException: xxxxxx