The thing is, a static analysis tool basically scans your code for violations of (what the author of the tool considers to be) "best practises". In this case, it's usually considered a "best practise" to have very shallow exception hierarchies.
The reason is that there's basically two times when you'll catch an exception. The first, is you want to catch the exception because you know how to handle it. For example:
try
{
return fetchDataFromFile();
}
catch(FileNotFoundException)
{
return defaultData;
}
In this case, you caught the FileNotFoundException
because you want to return "default data" when the file isn't found. In this situation, you typically catch a specific exception class - because that's the only type of exception you know how to handle (for example, if fetchDataFromFile
throws some other exception, you don't want it to return default data.
The other time you'll catch exceptions is at the very root of your thread,
try
{
doStuff();
catch(Exception e)
{
logException(e);
notifyUser(e);
}
In this case, you catch the root exception class, because you specifically want all exceptions so that you can log them, or notify the user.
There are very few situations where you need to do anything else.
Now, remember that this is a static analysis tool. It's job is to just flag "potential" problems to you. If you believe your situation is somehow different, then the idea is that you document why you think it's different and specifically disable that warning for that section of code (or that class or whatever).