JavaScript
x
10
10
1
def fu():
2
try:
3
print('hello')
4
fu()
5
except:
6
print('last hello')
7
exit()
8
9
fu()
10
So it should raise a recursion error after some time and when it does that I want to exit the whole code.
So what I am trying to get is:
JavaScript
1
5
1
hello
2
hello
3
4
last hello
5
But it gives something like:
JavaScript
1
6
1
hello
2
hello
3
4
last hello
5
last hello
6
So when it raises that error I want to do something and that’s all, just quit, no more trying
Advertisement
Answer
You need to add the base Exception type to the except and it will work.
JavaScript
1
9
1
def fu():
2
try:
3
print('hello')
4
fu()
5
except Exception:
6
print('last hello')
7
exit()
8
fu()
9