Answer the question
In order to leave comments, you need to log in
How to make an exception (try except) thrown every time an error occurs?
Hello. need help)
I need to handle divide-by-zero error. And then in another task, you need to display a variable that refers to this error .. In short, here:
-------------------------------- ------------------
try:
a = 5/0
print(a)
except:
print("Деление на 0")
print("Исключение было обработано")
#если я встречаю в коде где то эту ошибку и вывожу ее
#как ее обработать
print(a)
Деление на 0
Исключение было обработано
Traceback (most recent call last):
File "try_except.py", line 15, in <module>
print(a)
NameError: name 'a' is not defined
Answer the question
In order to leave comments, you need to log in
zaychonok_kisa , you have nothing to display in "a". 5 divided by 0, what should be output? Zero? If so then:
try:
a = 5/0
except ZeroDivisionError:
a = 0
print("Деление на 0")
print("Исключение было обработано")
#если я встречаю в коде где то эту ошибку и вывожу ее
#как ее обработать
print(a)
Divide by 0
Exception handled
0
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question