in Java7, the catch block has been upgraded to handle multiple exceptions in a single catch block.
code before Java7:
p>
catch (IOException ex) {
logger.error(ex);
throw new MyException(ex.getMessage());
catch (SQLException ex) {
logger.error(ex);
throw new MyException(ex.getMessage());
}catch (Exception ex) {
logger.error(ex);
throw new MyException(ex.getMessage());
}
in Java7, we can catch all these exceptions with a catch
p>
p>
catch(IOException | SQLException | Exception ex){
logger.error(ex);
throw new MyException(ex.getMessage());
}
if multiple exceptions are handled with a catch block, they can be separated by a pipe, in which case the exception parameter variable ex is defined as final and cannot be modified. This feature will generate less bytecode and reduce code redundancy.
p>
finally welcome to visit my personal website: 1024s
p>
Read More:
- Spring’s restcontrolleradvice is invalid, and the aspect log cannot catch exceptions
- go :Multiple-value strconv.Atoi() (int, error) in single-value context
- Assignment under multiple single edges is not supported for synthesis
- Info:Memory module [DIMM] needs attention: Single-bit warning error rate exceeded, Single-bit fai…
- ORA-19502: write error on file “”, block number (block size=)
- Built on Ethereum, puppeth cannot be used to create the initial block, and an error is reported Fatal: Failed to write genesis block: unsupported fork ordering: eip15
- How to select the jar package version for Maven package when the jar package versions referenced by multiple modules are inconsistent
- Java get try, catch error information data
- Flume monitors a single append file in real time
- How do you set, clear and toggle a single bit in C?
- How to handle when select single is not allowed in loop
- Solution to the segmentation fault of single chain table in C language
- Solve the problem of multiple root tags in as
- error: declaration may not appear after executable statement in block
- syntax error on token “catch”,Identifier expected
- [graphics] exceptions in downloading and installing OpenGL in vs2017
- Mybatis passes in multiple parameters to mapper. And uses @param details to report an error
- Cannot read property ‘catch‘ of undefined“
- Several methods of executing multiple commands in Linux shell
- Three ways of single line and multi line comment in Python