Comprehensive understanding of exception handling

Comprehensive understanding of exception handling

 

Similarities and differences between global processing and event rollback in exception handling:

Commonality:

They all throw some kind of exception (uncatchable), so that the configured processor will be transferred to the exception page when the page is jumped, and the page will be rolled back according to the thrown exception.

 

opposite sex:

 

1. The jump page prompt is to throw at the control layer, configure the corresponding catcher in springmvc, and jump to the page

 

exception page

 

 

 

<%

        Exception exception = (Exception) request.getAttribute("exception");

        if (exception != null) {

        String str= exception.getMessage();

             out.print(str+"\n");

            //out.print(exception.getMessage()+"\n");

            /* for (StackTraceElement stackTraceElement: exception.getStackTrace()){

                out.print(stackTraceElement.toString()+"\n");

            } */

        }

    %>

 

 

2. The rollback of a thing is to throw the corresponding exception at the service layer (specify the kind of exception rollback, the default runningtime, generally specified as exception), and open the annotation scanner of the thing in the configuration file, so that it will be captured and returned as soon as it is thrown. roll

@Transactional(rollbackFor=Exception.class)

 

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=326480131&siteId=291194637