Hi,
Most of the times if issue is occurred on browse screen or any other screen or popup. Exception stacktrace are seen on the dialog box.
I want to show Some general error message like Some Error occur. I dont want to show Error description to the user.
fedorov
(Sergey Fedorov)
March 1, 2024, 11:20am
2
Hi Adnan,
What version of Jmix do you use?
You can customize the way Jmix handles the exceptions.
By providing your own handlers for any exception - subclass AbstractUiExceptionHandler and register it as a @Component
By customizing the dialog shown by the default exception handler. To do this you need to create your dialog class based on ExceptionDialog.
See this doc: Exception Handlers :: Jmix Documentation
Regards,
Sergey.
fedorov
(Sergey Fedorov)
March 1, 2024, 11:30am
4
For exception handling in Jmix 1.5.0 see this doc: Exception Handlers :: Jmix Documentation
Hi,
Can we create common custom message for all exceptions instead of declaring every exception or exception class name
fedorov
(Sergey Fedorov)
March 4, 2024, 2:46pm
6
To bypass the default process of calling exception handlers, you can override the handle method in your exception handler.
You may need to also set a higher precedence to your exception handler, for example, @Order(JmixOrder.HIGHEST_PRECEDENCE - 10).
Example:
@Component("demo_CustomExceptionHandler")
@Order(JmixOrder.HIGHEST_PRECEDENCE - 50)
public class CustomExceptionHandler extends AbstractUiExceptionHandler {
@Override
public boolean handle(Throwable exception, UiContext context) {
doHandle(exception.getClass().getName(), exception.getMessage(), exception, context);
return true;
}
@Override
protected void doHandle(String className, String message, @Nullable Throwable throwable, UiContext context) {
context.getNotifications().create(Notifications.NotificationType.ERROR)
.withCaption("Error")
.withDescription(message)
.show();
}
}
Hi fedrov, can you provide an example of how to create a dialog class based on ExceptionDialog, I want to make it modal, to disable the interaction with the screen until the user closes it. I’m using Jmix 1.5.5
adnan.khan
(Adnan Khan)
January 23, 2025, 4:50pm
8
Hi David,
You can use below code reference to create ExceptionDialog
public class UIExceptionHandler extends AbstractUiExceptionHandler {
public UIExceptionHandler()
{
//super("java.lang.IllegalStateException");
//super(DownloadedReportsEntityBrowse.class.getName());
super("java.io.IOException");
}
@Override
protected void doHandle(String className, String message, Throwable throwable, UiExceptionHandler.UiContext context) {
try {
context.getNotifications().create(Notifications.NotificationType.ERROR)
.withCaption("Error")
.withDescription("Some Error Occur")
.show();
throwable.printStackTrace();
} catch (Exception e) {
e.printStackTrace();
}
}
@Override
public boolean handle(Throwable exception, UiContext context) {
try {
List<Throwable> list = ExceptionUtils.getThrowableList(exception);
for (Throwable throwable : list) {
if (canHandle(throwable.getClass().getName(), throwable.getMessage(), throwable)) {
doHandle(throwable.getClass().getName(), throwable.getMessage(), throwable, context);
return true;
}
}
}
catch (Exception e){
}
return false;
}
}