On Fri, 27 Oct 2023 05:55:43 GMT, David Holmes <dhol...@openjdk.org> wrote:

>> It is still used in tests and we should ignore it like jtreg doing.
>
> Shouldn't this code first retrieve the current default exception handler, and 
> then check whether t is a virtual thread, and if so handle the exception as 
> appropriate (not sure System.exit is appropriate ..). Then for non-virtual 
> threads it delegates to the previous default handler.
> 
> final UncaughtExceptionHandler originalUEH = 
> Thread.getDefaultUncaughtExceptionHandler();
> Thread.setDefaultUncaughtExceptionHandler((t, e) -> {
>         if (t.isVirtual()) {
>             // ...
>         } else {
>             originalUEH.uncaughtException(t, e);
>         }
> });

There shouldn't be an original UHE. jtreg doesn't set it. The goal is to add 
this handler for all threads, not only virtual. 
Please note, that it is planned to add it only until the similar problem in 
jtreg is completely fixed. 
I thought to add something like 

Thread.setDefaultUncaughtExceptionHandler((t, e) -> {
  UHE.ecxeptionThrown = e;
}

...

 @Override
    public Thread newThread(Runnable task) {
        return VIRTUAL_TF.newThread(new Runnable() -> {
                task.run();
                if (UHE.ecxeptionThrown != null) {
                         throw new RuntimeException(UHE.ecxeptionThrown);
                }
            );
    }
}


So test actually throws exceptions. It might miss exceptions for threads that 
finish later than the main thread. but might it is ok.

-------------

PR Review Comment: https://git.openjdk.org/jdk/pull/16369#discussion_r1374790707

Reply via email to