Spring Frame work Wraps Checked exceptions inside RuntimeExceptions

Have this method call:

   ->
    simpleJdbcTemplate.queryForInt(SQL,null);
   ->

queryForInt()in sources SimpleJdbcTemplatecreates DataAccessExceptionwhich is an exception to the runtime. I want to propagate exceptions at the application presentation level, since working with Spring Spring Wraps Checked Exceptions inside RuntimeExceptionsI'm stuck here.

How can I do it?

Explanation 1:

Additional benefits provided by the JDBC abstraction Spring Framework framework- say that the Spring Framework takes care of everything except 3 and 6. 3 and 6 should be written by the application developer.

  1. Define Connection Settings

  2. Open connection

  3. Indicate statement

  4. Prepare and execute an expression

  5. Set up a loop to iterate over the results (if any)

  6. Do the work for each iteration

, , . , . , ().

+3
3

, ( , RuntimeException Error, RuntimeException Error ) unchecked exceptions (RuntimeException Errors Throwable).

, - :

try {
//... processing
} catch(Exception/RuntimeException e) {
// propagate the exception to the view in a meaningful manner
}

, - .

, Java, , , , :

try {
//...spring code
} catch(DataAccessException e) {
throw new Exception(e);
}

.

+1

, Spring , , . - DataAccessExceptions, :

try {
    // query logic
} catch (DataAccessException ex) {
    // handle the exception
}

Spring MVC, , ExceptionResolver. , , . , , .

+7

? , getCause() RuntimeException, , . "throws" , SimpleJdbcTemplate, DataAccessException , .

+1
source

Source: https://habr.com/ru/post/1708366/


All Articles