On my own project, the first exception that pops up is com.haulmont.cuba.core.global.DeletePolicyException
so I’ve made my own class out of AbstractUiExceptionHandler
but doHandle()
is not being triggered at all so I’m not able to handle the exception.
Here’s the class code:
package com.sample.samp.web;
import com.haulmont.cuba.gui.Notifications;
import com.haulmont.cuba.gui.exception.AbstractUiExceptionHandler;
import org.apache.commons.lang3.StringUtils;
import org.springframework.stereotype.Component;
import javax.annotation.Nullable;
@Component("sample_FKErrorHandler")
public class FKExceptionHandler extends AbstractUiExceptionHandler {
public FKExceptionHandler(){
super("com.haulmont.cuba.core.global.DeletePolicyException", "java.sql.SQLIntegrityConstraintViolationException","org.postgresql.util.PSQLException",
"com.haulmont.cuba.core.global.RemoteException","java.lang.reflect.InvocationTargetException","com.vaadin.server.ServerRpcManager$RpcInvocationException","com.haulmont.cuba.core.global.RemoteException");
}
@Override
protected void doHandle(String className, String message, @Nullable Throwable throwable, UiContext context) {
if (throwable != null) {
context.getDialogs().createExceptionDialog()
.withThrowable(throwable)
.withCaption("error")
.withMessage("error")
.show();
} else {
context.getNotifications().create(Notifications.NotificationType.ERROR)
.withCaption("error")
.withDescription("error")
.show();
}
}
@Override
public boolean handle(Throwable exception, UiContext context) {
return super.handle(exception, context);
}
@Override
protected boolean canHandle(String className, String message, @Nullable Throwable throwable) {
return StringUtils.containsIgnoreCase(message, "some error");
}
}