As others have said, you should assume that every line of code can throw an exception if you have not proven that this is not possible. The best question is: "What are you planning to do about this?"
In general, you should not catch any exceptions at all.
Of course, everything else is an exception to this rule. It makes sense to catch an exception to register it (if your environment does not do this for you, as ASP.NET does). It makes sense to catch an exception to replace it with another exception that provides more detailed information about the context:
public int GetConfiguredInteger(string name) { string s = null; try { s = GetStringFromConfigFile(name); } catch (IOException ex) { throw new Exception(String.Format( "Error in configuration file foo.config when processing {0}", name), ex); } return int.Parse(s); }
The caller could not know that an IOException was thrown by the configuration file unless you told them. Also notice how I ignored all exceptions not related to file I / O. In particular, note that int.Parse is not even inside a try / catch block.
There are a small number of other exceptions, but the main idea for catching exceptions is this: do not do this if it will not be worse if you did not.
John saunders
source share