0

The problem with the transmission of the exceptions in the Spring WebFlow 3

The pre-define the method throw an exception like the following:

public class MyBusinessException extends BusinessException {

    private static final long serialVersionUID = -1276359772397342392L;

    private Long min = null;

    private Long max = null;

    public static final String CODE_1 = "code.1.business.exception";

    public static final String CODE_2 = "code.2.business.exception";

    public MyBusinessException (String code, Exception ex) {
        super(code, ex);
    }

    public MyBusinessException (String code) {
        super(code);
    }

    public MyBusinessException (Long min, Long max, final String messageCode) {
        super(messageCode);
        this.min = min;
        this.max = max;

    }

    public Long getMin() {
        return min;
    }

    public Long getMax() {
        return max;
    }

}

The transition after the capture of an exception in webflow looks like this

<transition on-exception="MyBusinessException" to="start" >
            <evaluate expression="actionService.showError(flowExecutionException)" result="flashScope.refreshError"/>
</transition>

In action showError would retrieve the message from the exception and the min and max values​​. How to do it. Please help.

public String showError(FlowExecutionException flowExecutionException) {
        flowExecutionException.?
        return "someString";
    }

1 Answer 1

1

There are a couple ways you can do this.

The best way, if you can do it, is to implement/override MyBusinessException's toString() method. Every Exception has a toString() method, so whatever FlowExecutionException you get in your showError method you'll still get a meaningful description of the error in the String.

public String showError(FlowExecutionException flowExecutionException) {
    return flowExecutionException.toString();
}

A fallback method, e.g. if you don't have access to the code inside MyBusinessException, would be to use the instanceof operator to determine whether MyBusinessException is a valid class, superclass, interface or superinterface of your FlowExecutionException.

public String showError(FlowExecutionException flowExecutionException) {
    if (flowExecutionException instanceof MyBusinessException) {
        MyBusinessException usableException = (MyBusinessException)flowExecutionException;

        int min = usableException.getMin();
        int max = usableException.getMax();

        return "MyBusinessException min="+min+", max="+max;

    } else return flowExecutionException.toString();
}
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.