Error divided by 0 Processing of ZeroDivisionError 2

import traceback, sys

number1 = 100
number2 = 0

print('start')

try:
    answer = number1 / number2
    print(answer)
except ZeroDivisionError as e:
    print('It does not break at 0.')
    sys.stderr.write(traceback.format_exc())
finally:
    print('end')

Execution result


start
It does not break at 0.
end

Run-time error


Traceback (most recent call last):
  File "Main.py", line 9, in <module>
    answer = number1 / number2
ZeroDivisionError: division by zero

By doing this Even if you only look at the output tab It is easy to understand what kind of error is occurring.

Also, If you look at the runtime error tab, You can check the details of the error.

Recommended Posts

Error divided by 0 Processing of ZeroDivisionError 2
Error divided by 0 Handling of ZeroDivisionError
Grayscale by matrix-Reinventor of Python image processing-
Change processing by user input of dialog
Image processing by matrix Basics & Table of Contents-Reinventor of Python image processing-
Communication processing by Python
Various processing of Python
Basic processing of librosa
Visualization of data by prefecture
Parallel processing with Parallel of scikit-learn
Calculation of similarity by MinHash
Image processing by python (Pillow)
Post processing of python (NG)
Straight line drawing by matrix-Inventor's original research of Python image processing-