How do I display database trigger errors on a web application through Payara5

倾然丶 夕夏残阳落幕 提交于 2020-02-06 11:38:44

问题


This is a standard error I receive for all Errors parsed from Database Triggers. I use Payara5 as the Application Server and Netbeans 8.2 IDE. In the instance on the picture, it was supposed to display "ID Number mandatory for applicants order that 18 years of age".

How do I make sure that the exact error as in the trigger, appears on the Web Application?


回答1:


Given your stacktrace it looks like you need to remove the ExceptionUtils.findRootException(ex).getMessage() and just use ex.getMessage() since the thrown topmost Exception already contains the message that you need.

I would try with the following code when an Exception is thrown:

catch (Exception ex) {
    JSFUtils.addMessageSessionError(
        ExceptionUtils.formatException(AdHocTools.getCurrentMethodName(),
        ex.getMessage());
}

However, ExceptionUtils.findRootException(ex).getMessage() might be there for a reason. There are cases where the topmost Exception is pretty general (e.g. an EJBException) and you really need to get to the root exception to get a meaningful message.

You could also try with this code which returns an SQLException if applicable and in other cases the root Exception.

catch (Exception ex) {
    Throwable rootCause = ex;
    while (rootCause.getCause() != null && rootCause.getCause() != rootCause) {
        if ( rootCause instanceof java.sql.SQLException ) {
            break;
        }
        rootCause = rootCause.getCause();
    }
    JSFUtils.addMessageSessionError(
        ExceptionUtils.formatException(AdHocTools.getCurrentMethodName(),
            rootCause.getMessage());
}


来源:https://stackoverflow.com/questions/59005635/how-do-i-display-database-trigger-errors-on-a-web-application-through-payara5

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!