1

I was writing a Python tutorial in Jupyter Notebook and was trying to demonstrate why one should never use a bare except. My example was

try:
    exit(0)
except:
    print('Did not exit')

The idea was that exit would raise a SystemExit which inherits from BaseException. However, the kernel still died when I ran the cell.

Running this code in IPython displays

Did not exit

What does exit do in Jupyter Notebook?

Daniel Walker
  • 6,380
  • 5
  • 22
  • 45
  • Does this answer your question? [What does \`exit\` keyword do in Python3 with Jupyter Notebook?](https://stackoverflow.com/questions/53676034/what-does-exit-keyword-do-in-python3-with-jupyter-notebook) – Ake Apr 07 '23 at 03:38
  • @Ake, I saw that post but it didn't explain what `exit` does under the hood. – Daniel Walker Apr 07 '23 at 03:40

0 Answers0