You can look inside the exception itself:
>>> def f(): ... f() ... >>> try: ... f() ... except RuntimeError as re: ... print re.args, re.message ... ('maximum recursion depth exceeded',) maximum recursion depth exceeded
I do not think that you can distinguish between this and something, just pretending to be an exception as an exception with excess recursion (Runtime). message deprecated, so args is probably the best option and compatible with Python-3.
Update: There is a special RecursionError in Python 3.5 that you can catch instead.
DSM
source share