0
0

More than 1 year has passed since last update.

Exception classのgetMessage

Last updated at Posted at 2023-01-17

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
0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0