@Override
@Async
public void asyncExceptionTest() {
int i=1/0;
}
How can I log this using Spring Async framework without having to put try catch around every async method? It doesn’t seem to pass to the DefaultUncaughtExceptionHandler like normal.
@Asyncmethods can be configured with a customExecutorto log any thrown exceptions.The following code implements this pattern. Any method tagged with
@Asyncwill use theExecutorreturned by the methodpublic Executor getAsyncExecutor(). This returns theHandlingExecutorwhich takes care of all logging (in this case it just prints the word “CAUGHT!” but you can replace with logging.