Is it antipattern to catch all exceptions all at once?
What is bad such an approach:
try { foo(); } catch (Exception e) { // handle <-- разумеется, тут реальная обработка, а не подавление исключений } Without specifying what specific exceptions I want to handle.
Suppose I have in try ... catch wrapped code working with the file system, for specifics - copying the file .
The documentation has as many as 8 options for exceptions that this method can throw out - should a good programmer carefully write out all possible exceptions and periodically check that Microsoft will not add new ones?
I heard that you can generalize exceptions and not to write PathTooLongException , DirectoryNotFoundException and DirectoryNotFoundException every time, but once to handle an IOException from which they all inherit. This helps to reduce the number of catch blocks, but not by a lot (in the example with File.Copy, it can be reduced by 4, a total of 8). Is this the correct approach or does it also have its own nuances?
DirectoryNotFoundExceptionis specified twice. I do not know sisharp, so I can not fix it. - val