'specified try except with datetime.date()
I am trying to catch the exceptions with incorrect month and days and negative years of date() from the datetime module but when I use ValueError exception I can't be specific. How can I specify my exceptions?
from datetime import datetime, date, timedelta
a = int(input('Year:'))
b = int(input('Month:'))
c = int(input('Day:'))
try:
a_date = date(a, b, c)
print(a_date.strftime("%d/%m/%Y"))
except ValueError:
print('month must be in 1..12')
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|
