print ("enter 2 numbers to divide ")
x = input ()
y = input ()
try :
div = int (x)/ int (y)
print ( x + ' / ' +y +' = ' +str(div))
mul = int (x)* int (y)
print ( x + ' * ' +y +' = ' +(str(mul)))
except ZeroDivisionError:
print ("2nd number can not be 0")
#except SyntaxError:
print ("try again inputs are wrong")
except ValueError:
print ("try again inputs are wrong Value error")
except:
print ("number can not be blank")
This is an example code. I want to understand , what ever error it is , it does not go to default if ValueError is specified. To test it I added the SyntaxError exclussively , even then when a sysntax error occures (like . / ` ) where divition can not happen and in compiler it is a syntax error still in goes under value error block.
One more example,
>>> s/a
Traceback (most recent call last):
File "<pyshell#29>", line 1, in <module>
s/a
NameError: name 's' is not defined
This inputs also take the output to "Value Error " instead of default.
Even ,
>>> `/`
SyntaxError: invalid syntax
In this case even though syntax error is defined , it takes the output to "valueerror" (if defined ) or default rather than going inside "SyntaxError" error block of the code.
Can any one tell me why ? I checked in hierarchy and a few example website, but nothing I understood what is causing this.