Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Continue in catch block

Is this:

// retry
for (int i = 0; i < length; ++i)
{
    try
    {
        sqlCommand.ExecuteNonQuery();
    }
    catch (SqlException e)
    {
        if (e.Number == 64)
        {
            continue;
        }
    }
}

equivalent to:

// retry
for (int i = 0; i < length; ++i)
{
    try
    {
        sqlCommand.ExecuteNonQuery();
    }
    catch (SqlException e) { }
}

(since the loop will continue anyway in latter case)

What is the difference (if any)?

like image 855
Annie Avatar asked Dec 11 '22 05:12

Annie


1 Answers

continue let you to skip the remaining statments in the current loop, and jump to the next iteration.

Given the code we have right now, it makes no difference. Since there is no more code after if (e.Number == 64) { continue; }.

like image 185
Xiaoy312 Avatar answered Dec 21 '22 03:12

Xiaoy312