Easy question on error catching

Sean Berry sean_berry at cox.net
Mon Apr 12 14:20:27 EDT 2004


I am still relativly new to python.

I have written a pretty extensive program that works like a charm, doing a
lot of operations on all incomming email.

My problem is this:
I have a portion of code that does some stuff with the date of the email.
However, beacause so many people forge things like dates in spam emails I am
getting an error when the program gets to the following line.

x = int(t)

In a couple of cases, people have forged the date to include words that have
nothing to do with the date.
I get a:
ValueError: invalid literal for int(): <stuff that is forged>

So, how do I catch this error so that I can do something else with it?

Is it as simple as
try:
    x = int(t)
except:
    something else

or do I need to catch a ValueError specifically?

Sorry about the easy question.  Thanks in advance.





More information about the Python-list mailing list