Repeated interception allows you to catch multiple exceptions in the same
catchstatement.
How and why to catch multiple exceptions in a single catch statement?
Repeated interception allows you to catch multiple exceptions in the same
catchstatement.
How and why to catch multiple exceptions in a single catch statement?
It is convenient when you need to list a lot of exceptions in one block:
catch (IOException | SQLException ex) { logger.log(ex); throw ex; } All the same, the original question was a bit different:
How and why to catch multiple exceptions in a single catch statement?
This is done for error typing, a simple example:
try { FileReader fr = new FileReader("test.txt"); int i; while ((i=fr.read()) != -1){ System.out.print((char) i); } } catch(FileNotFoundException fnfex) { //не найден файл } catch(IOException ioex) { //ошибка чтения } That is, the developer is given the opportunity to diagnose the error depending on the type of error that occurred.
Source: https://ru.stackoverflow.com/questions/618140/
All Articles