The general philosophy of exceptions in any language is that they report exceptional circumstances. You must use them accordingly.
If you end all function calls with a try block, something is wrong. Exceptions are precisely designed to provide logical error handling and do not require the programmer to track all possible error paths. Therefore, you should catch exceptions precisely at those points where you can adequately respond to them.
If you can't think of anything better than aborting and propagating the error, then there is no point in catching the exception. On the other hand, if there are some mistakes that you can reasonably react with, catch them and collapse something else.
A typical example is the processing of a large number of files. If there is an error in the parsing logic, you cannot do anything, even if many parsing of functions can occur during parsing. However, in the main loop, you can try analyze each file, and if there is an exception, you will catch it, skip the file and move on to the next.
If you are writing a library function, you may need one last try block surrounding your entire function; which is somewhat up to you. Just clearly document what exceptions the user should expect from your library.
source share