Hi,
I want to add a custom exception for uncought exceptions. For example when there occurs ClassCastException exception, in stead of showing that as a dialogue box it should show an error notification with the message as "Application Error occurred. Please check with your administrator. "
Please suggest how to implement this feature.
Thanks,
Saumm
krivopustov
(Konstantin Krivopustov)
August 4, 2016, 7:22am
#2
Hi I tried to create a custom exception handler by following the steps in the docs. Unfortunately it’s not working. I kept the handler in web module and the codes are as follows.
mport com.haulmont.cuba.gui.WindowManager;
import com.haulmont.cuba.gui.components.Frame;
import com.haulmont.cuba.gui.exception.AbstractGenericExceptionHandler;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Component;
import javax.annotation.Nullable;
/**
* Created by Saumm on 8/4/2016.
*/
@Component("cuba_ClassCastExceptionExceptionHandler")
public class ClassCastExceptionExceptionHandler extends AbstractGenericExceptionHandler {
private Logger logger = LoggerFactory.getLogger(ClassCastExceptionExceptionHandler.class);
public ClassCastExceptionExceptionHandler(){
logger.info("Custom exception handler");
}
@Override
protected boolean canHandle(String className, String message, @Nullable Throwable throwable) {
return true;
}
@Override
protected void doHandle(String className, String message, @Nullable Throwable throwable, WindowManager windowManager) {
String msg = "Exception Occured";
windowManager.showNotification(msg, Frame.NotificationType.ERROR_HTML);
}
}
Please tell me where I am missing in the implementation.
krivopustov
(Konstantin Krivopustov)
August 5, 2016, 5:53am
#4
You haven’t defined the class of exception which should be handled.
Do it in the constructor:
public ClassCastExceptionExceptionHandler(){
super(ClassCastException.class.getName());
logger.info("Custom exception handler");
}
or
public ClassCastExceptionExceptionHandler(){
super("java.lang.ClassCastException");
logger.info("Custom exception handler");
}