Short answer
Catch the exceptions that you can deal with then and there, rethrow what you cannot.
Long answer
He called the exception handling code for some reason: whenever it is tempting to write a catch , you must have a good reason to catch the exception in the first place. The catch indicates your intention to catch the exception and then do something. Examples of something with this include, but are not limited to:
Retrying the operation that caused the exception. This may make sense in the case of an IOException and other problems that may be temporary (for example, a network error in the middle of trying to upload a file to the server. Perhaps your code should retry downloading several times).
Exception record. Yes, journaling is considered something. You may also want to throw the original exception again after it is registered so that another code can still handle this exception, but it depends on the situation.
An exception wrapper in another exception, more suitable for your class interface. For example, if you have a FileUploader class, you can wrap an IOException in a more general UploadFailedException so that classes using your class do not need to know in detail how your loading code works (the fact that it throws a IOException is technically an implementation detail) .
If the code cannot intelligently do anything about the problem at the point where it occurs, then you should not catch it at all.
Unfortunately, such strict rules never work in 100% of cases. Sometimes, the third-party library that you use throws checked exceptions that you really don't like or that will never happen. In these cases, you can get rid of using an empty catch that does not run any code, but this is not recommended for eliminating exceptions. At the very least, you should add a comment explaining why you ignore the exception (but like CPerkins in the comments, “never say never.” You want to actually register these types of exceptions “never happen”, so just in case such an exception occurs, you know about it and you can continue the study).
However, the general rule is that if the method you are in cannot do something reasonable with the exception (write it down, restart, repeat the operation, etc.), then you should not write a catch generally. Let the invocation method deal with the exception. If you are dealing with checked exceptions, add an excluded exception to the throws your method, which tells the compiler to throw the exception up to the calling method, which may be better suited to handling the error (the calling method may have more context, so it can better understand how to handle an exception).
It is usually useful to add try...catch to your main method, which will catch all exceptions that your code cannot handle, and report this information to the user and gracefully exit the application.
And finally, don't forget about finally
Also keep in mind that even if you are not writing a catch , you still have to write a finally block if you need cleansing code to run regardless of whether the operation you are trying to execute exceptions or exceptions is performed. A common example is opening a file in a try block: you still want to close the file, even if an exception occurs, and even if your method does not catch the exception. In fact, another general rule that you can see in textbooks and books is that try...finally blocks should be more common in try...catch blocks in your code, precisely because catch blocks should only be written when you really can handle the exception, but finally blocks are needed when your code needs to be cleaned after itself.