O'Reilly logo

Java 9 Concurrency Cookbook - Second Edition by Javier Fernández González

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

How to do it...

Follow these steps to implement the example:

  1. First of all, we have to implement a class to treat unchecked exceptions. This class must implement the UncaughtExceptionHandler interface and implement the uncaughtException() method declared in this interface. It's an interface enclosed in the Thread class. In our case, let's call this class ExceptionHandler and create a method to write information about Exception and Thread that threw it. The following is the code:
        public class ExceptionHandler implements UncaughtExceptionHandler {           @Override           public void uncaughtException(Thread t, Throwable e) {             System.out.printf("An exception has been captured\n");             System.out.printf("Thread: %s\n",t.getId());  System.out.printf("Exception: ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required