Is there a cleaner way to ensure I am not writing duplicate data? I have the following loop which uses Idiorm to write to a table from a PHP Slim application:

foreach($jobs-&gt;get_items() as $job) {

        echo $job-&gt;get_title().'&lt;br /&gt;';
        $jobRow = ORM::for_table('jobs')-&gt;create();
        $jobRow-&gt;guid = $job-&gt;get_id(TRUE);
        $jobRow-&gt;url = $job-&gt;get_link();
        $jobRow-&gt;description = $job-&gt;get_description();
        $jobRow-&gt;pubdate = $job-&gt;get_date();
        echo $job-&gt;get_date();

        try {
        $jobRow-&gt;save();
        } catch (exception $e) {
            continue;
        }
    }


It feels a bit hacky to be using continue in a try/ catch block. Is there a better way to avoid a MYSQL constraint violation without having to query the table? get_id() returns an md5 hash of the guid in an rss feed which is actually a unqiue URL. I have a UNIQUE index on that field in my table.
How exceptional is this error? What do you want to do when this happens?

If it's rare and you don't want to do anything, then:


Only catch the actual exception (maybe it's PDOException).
Remove the continue which serves no purpose here and could confuse the reader.
Make sure you don't fail silently when the error is not a violation error.


Your code will look like this:

try {
    $jobRow-&gt;save();
} catch (PDOException $e) {
    if(!isAnExpectedViolation()) {
        // I still need to do something about it!
    }
}


If it's really frequent, you may want to check if it's going to violate the constraint before running the query. If it's frequent and you want to tell about it to the user, put it into an if and act accordingly.