Figure 9 Displaying Exceptions Gracefully
กก
private void ShowSqlCeErrors(SqlCeException exSql)
{   
    StringBuilder oSBMsg = new StringBuilder();

    int i = 0;

    foreach (SqlCeError err in exSql.Errors)
    {
        i++;
                
        oSBMsg.Append("\n Error # " + i + " of " + 
            exSql.Errors.Count);
        oSBMsg.Append("\n Error Code: " + err.HResult);
        oSBMsg.Append("\n Message   : " + err.Message);
        oSBMsg.Append("\n Minor Err.: " + err.NativeError);
        oSBMsg.Append("\n Source    : " + err.Source);
    
        for (int j = 0; j < err.NumericErrorParameters.Length; 
            j++)
        {
            if (err.NumericErrorParameters[j] != 0) 
            {
                oSBMsg.Append("\n Numeric Parameter: " + 
                    err.NumericErrorParameters[j]);
            }
        }
  
        for (int k = 0; k < err.ErrorParameters.Length; k++)
        {
            if (err.ErrorParameters[k] != string.Empty) 
            {
                oSBMsg.Append("\n Error Parameter  : " + 
                    err.ErrorParameters[k]);
            }
        }
        MessageBox.Show(oSBMsg.ToString());
        oSBMsg.Remove(0, oSBMsg.Length);
    }
}