* BAEL-1044 - Introduction to NoException * BAEL-1044 - Introduction to NoException * BAEL-1044 - Introduction to NoException * BAEL-1044 - Introduction to NoException * BAEL-1044 - Introduction to NoException * Update pom.xml Add missing </dependency>
25 lines
674 B
Java
25 lines
674 B
Java
package com.baeldung.noexception;
|
|
|
|
import com.machinezoo.noexception.ExceptionHandler;
|
|
import org.slf4j.Logger;
|
|
import org.slf4j.LoggerFactory;
|
|
|
|
public class CustomExceptionHandler extends ExceptionHandler {
|
|
|
|
private Logger logger = LoggerFactory.getLogger(CustomExceptionHandler.class);
|
|
|
|
@Override
|
|
public boolean handle(Throwable throwable) {
|
|
|
|
if (throwable.getClass()
|
|
.isAssignableFrom(RuntimeException.class)
|
|
|| throwable.getClass()
|
|
.isAssignableFrom(Error.class)) {
|
|
return false;
|
|
} else {
|
|
logger.error("Caught Exception ", throwable);
|
|
return true;
|
|
}
|
|
}
|
|
}
|