0
Zero o type Error ?
try: variable = 10 print (variable + "hello") print (variable / 0) except ZeroDivisionError: print ("Divided by zero") except (ValueError, TypeError): print ("An error occurred") I don't understand, with this division value, shouldn't ZeroDivisionError skip? but instead I get the error occurred
7 Respostas
+ 4
The following code does catch all exceptions and ahows the error message:
try:
variable = 10
print (variable + "hello")
print (variable / 0)
except Exception as e:
print('the following error occurred: ',e)
+ 2
In programming, we can't divide any number with zero. If you do you will get the error and in python, this error called ZeroDivisionError.
but in the second line, you are adding string with an integer which is TypeError that's why you getting an error occurred.
+ 2
Because the error is rising due to line 2 ( print(variable + 'hello') ) as you are trying to add variables of different datatype thus generating value error.
+ 2
Thank all
+ 1
TypeError happens first so it has to handle it first.
+ 1
First exception is in
print( variable + "hello") type error..