I have a web service running embedded Undertow, and some of the handlers make use of the common Undertow pattern of offloading requests to worker threads:
if (exchange.isInIoThread()) {
exchange.dispatch(this);
}
This is great for performance, but it presents a problem in dealing with error handling. I created a custom ErrorHandler that maps Java exceptions to HTTP response types and log levels, and allows the API handlers themselves to just bubble up exceptions and not worry about handling them. Unfortunately for requests that are dispatched to a worker thread, they never make it into the ErrorHandler, always resulting in a 500 error if they throw an exception. Is there any way to catch exceptions thrown from worker threads, or do I have to implement exception handling in each API handler?