Source error handling

Energy.Source.Error classifies database exceptions into retryable and non-retryable error categories.

Result

Energy.Source.Error.Result contains boolean flags for each error category:

Property Description
Access Access denied.
Timeout Command timeout.
Damage Connection is damaged.
Connection Connection error.
Deadlock Deadlock occurred.
Syntax Syntax error.
Miss Missing object (column, table, procedure).
Operation Operation error.

Catch

try
{
    command.ExecuteNonQuery();
}
catch (Exception exception)
{
    Energy.Source.Error.Result result = Energy.Source.Error.Catch(exception, command);

    if (result.Deadlock || result.Timeout || result.Damage)
    {
        // operation may be retried
    }
    else if (result.Syntax || result.Miss)
    {
        // operation is unlikely to succeed
    }
}

Error number

int[] numbers = Energy.Source.Error.GetErrorNumber(exception);
foreach (int number in numbers)
{
    Console.WriteLine(number);
}

Known error numbers

The Catch method recognizes common error codes from MySQL and SQL Server, including:

  • 1042 — MySQL connection failure

  • 1045 — MySQL access denied

  • 1205 — SQL Server deadlock

  • -2 — SQL Server timeout

  • 207, 208, 2812 — SQL Server missing object

  • 102, 156, 245 — SQL Server syntax errors

See also

  • core-source