Exception Handling in CUBA

Hello,

I want to react on OptimisticLockingException in an EntityEditor by for example showing a message. How should that be done using CUBA. I read the documentation about Exceptions but there all Handling is done in a seperate Bean. Is this necessary.

Any help appreciated.

Hi Stephan,

The OptimisticExceptionHandler bean is used for handling the exception globally. If you want to react to this exception just in one screen, override its commitAndClose() or commit() method (it depends on whether your screen is closed on commit, see diagrams here). For example:

public class CustomerEdit extends AbstractEditor<Customer> {

    @Override
    public void commitAndClose() {
        try {
            super.commitAndClose();
        } catch (Exception e) {
            showMessageDialog("Error", "The customer was modified in another transaction", MessageType.WARNING);
            throw new SilentException();
        }
    }
}