Parsing date strings, inferring the year such that the date is not in the future I got this program that I am working on and in it, I got a section that has a try statement and two error except statements. 

try:
    ...
    if ...: raise SyntaxError
except SyntaxError:
    ...
except ValueError:
    ...


The thing is that the SyntaxErrors are technically ValueErrors, but the errors occur for different reasons, therefore need different code to solve/get around the problem. So in order to prevent the code in all the "excepts" from being executed, I had to separate/make the type of Errors different. Is it okay to do that even though the SyntaxErrors are techincally ValueErrors, that I label them as SyntaxErrors? Or is there a method in solving this problem?

Here is the code of the program:

from datetime import datetime

today = datetime(2019, 1, 1).date() 
this_year = 2019
last_year = this_year - 1

text = ["Dec 31 ", "@@@@@@@@@@@@@@@@@@@@@Dec 31 "]

for line in text:
    date_str = line
    try:
        date = datetime.strptime(date_str + str(this_year), "%b %d %Y").date()
        if date &gt; today: raise SyntaxError
        print("+", date)
    except SyntaxError:
        date = datetime.strptime(date_str + str(last_year), "%b %d %Y").date()
        print("-", date)
    except ValueError:
        print("abnormality")
        continue
Obtaining a date that is in the future is in no way a "syntax error", and it would be inappropriate to raise a SyntaxError.  Instead of abusing the exception-handling mechanism, you should just use a conditional.

for date_str in text:
    try:
        date = datetime.strptime(date_str + str(this_year), "%b %d %Y").date()
        if date &lt;= today:
            print("+", date)
        else:
            date = datetime.strptime(date_str + str(last_year), "%b %d %Y").date()
            print("-", date)
    except ValueError:
        print("abnormality")


Note that you might be misinterpreting some ValueErrors as abnormalities.  For example, "Feb 29 2021" would cause a ValueError, but then you would never get a chance to try "Feb 29 2020", which is a valid day in a leap year.