DEV Community

Discussion on: Code Smell 132 - Exception Try Too Broad

Collapse
 
otumianempire profile image
Michael Otu
birthYear= int(input('Birth year:'))
birthMonth= int(input('Birth month:'))
birthDay= int(input('Birth day:'))
Enter fullscreen mode Exit fullscreen mode

Wouldn't any of these also raise an error if the user enters a non-integer character?

Again in

print(datetime.date(int(birthYear), int(birthMonth), int(birthDay)))
Enter fullscreen mode Exit fullscreen mode

the data above are been cast to int.

So I think you meant,

birthYear= input('Birth year:')
birthMonth= input('Birth month:')
birthDay= input('Birth day:')


try: 
    print(datetime.date(int(birthYear), int(birthMonth), int(birthDay)))
except ValueError as e:
   ....
Enter fullscreen mode Exit fullscreen mode
Collapse
 
mcsee profile image
Maxi Contieri

Yes. You are right.
I am not very fluent in Python.
I try to use as many languages as possible to show code smells are language independent.
Thank you very much for the correction