0

In Python, we can write two kinds of exceptions handling logics

First one is bare except:

try:
   do_something()
except:
   error_handling()

Another one is First broad except:

try:
   do_something()
except Exception:
   error_handling()

What's the actual difference between them?

Quanlong
  • 24,028
  • 16
  • 69
  • 79
  • Does this answer your question? [Difference between except: and except Exception as e: in Python](https://stackoverflow.com/questions/18982610/difference-between-except-and-except-exception-as-e-in-python) – kaya3 Apr 23 '20 at 17:18

1 Answers1

2

The top of the exception hierarchy is not Exception, but BaseException, which has four subclasses:

  • Exception
  • GeneratorExit
  • SystemExit
  • KeyboardInterrupt

A bare except: is equivalent to except BaseException:.

chepner
  • 497,756
  • 71
  • 530
  • 681