from datetime import datetime bad_st_mtime = -100000000000.0 # Try converting a bad timestamp into a datetime try: datetime.fromtimestamp(bad_st_mtime) except ValueError: # This is the error that should be raised, so we ignore it pass