Catching exception from a called function
<p>I have a function that reads a CSV, checks the values in the rows, and if everything is okay, it writes the rows to a new CSV file.  I have a few validation functions I'm calling within my main function to check the value and format of the rows.  </p>

<p>I'm trying to implement my main function in a way so that when I call the other validation functions and something doesn't check out, I skip writing that row entirely.  </p>

<pre><code>#main function
for row in reader:
    try:
        row['amnt'] = divisible_by_5(row['amnt'])
        row['issue_d'] = date_to_iso(row['issue_d'])
        writer.writerow(row)
    except:
        continue

#Validation function
def divisible_by_5(value):
    try:
        float_value = float(value)
        if float_value % 5 == 0 and float_value != 0:
            return float_value
        else:
            raise ValueError
    except ValueError:
        return None
</code></pre>

<p>At the moment, the writer is still writing rows that should be skipped.  For example, if a number is not divisible by 5, instead of skipping that row, the writer is just writing <code>''</code>.</p>

<p>So, how can I handle the exception (<code>ValueError</code>) raised in <code>divisible_by_5</code> in my for loop so I don't write lines that raise an exception?      </p>