I can't catch sys.exit()

Viewed 175

I want to prevent a python program to quit when it calls sys.exit, but the following solution doesn't work:

Python 3.9.1 (tags/v3.9.1:1e5d33e, Dec  7 2020, 17:08:21) [MSC v.1927 64 bit (AMD64)] on win32
>>> import sys
>>> try:
...     sys.exit()
... except SystemExit:
...     print('asd')
...
   
Process finished with exit code 0

I've also tried BaseException, but it quits anyway. It seems like it's not an exception at all. How is this possible? Is every guide on the argument wrong? It can't be.

0 Answers
Related