Because it is terribly non-specific, and it does not allow you to do anything interesting with the exception. Moreover, if you catch every exception, there can be many exceptions that occur that you don’t even know what is happening (which could lead to your application crashing if you really don’t know why). You should be able to predict (either through reading documentation or experimenting) which particular exceptions you should handle and how to handle them, but if you blindly suppress all of them from the very beginning, you will never know.
So, for a popular query, here is an example. The programmer writes Python code and it receives an IOError . Instead of investigating further, she resolves all the exceptions:
def foo(): try: f = open("file.txt") lines = f.readlines() return lines[0] except: return None
She does not understand the question in her own way: what if the file exists and is accessible, but it is empty? Then this code will raise an IndexError (since the lines list is empty). Therefore, she will spend hours pondering why she gets None back from this function when the file exists and is not locked, not understanding what would be obvious if it were more specific in detecting errors, namely, that it accesses the data, which may not exist.
Rafe Kettler
source share