SqlCeException.Message - why does it hide Exception.Message?

  • Thread starter Thread starter Jon Skeet [C# MVP]
  • Start date Start date
J

Jon Skeet [C# MVP]

I've just been trying to log exception messages, and discovered that
SqlCeException.Message hides Exception.Message. Why is this? What on
earth is the benefit of the base Exception.Message always returning an
empty string? It's making the logging code much more tortuous -
although admittedly I'm now walking through all the errors and logging
each of them in turn.
 
this will change in sqlce 3.0... in the mean time

internal static void SqlCeExceptionHandling (SqlCeException e)
{
SqlCeErrorCollection errorCollection = e.Errors;
StringBuilder bld = new StringBuilder();
Exception inner = e.InnerException;
if (null != inner)
{
MessageBox.Show("Inner Exception: " + inner.ToString().Replace(
ApplicationSettings.DBPassword, "DBPassword"));
}
foreach (SqlCeError err in errorCollection)
{
bld.Append("\n Error Code: " + err.HResult.ToString("X"));
bld.Append("\n Message : " + err.Message);
bld.Append("\n Minor Err.: " + err.NativeError);
bld.Append("\n Source : " + err.Source);
foreach (int numPar in err.NumericErrorParameters)
{
if (0 != numPar) bld.Append("\n Num. Par. : " + numPar);
}
foreach (string errPar in err.ErrorParameters)
{
if (String.Empty != errPar) bld.Append("\n Err. Par. : " +
errPar);
}
try
{
// I put this here to replace any password strings as the error
tends to show it!!!
MessageBox.Show(bld.ToString().Replace(
ApplicationSettings.DBPassword, "DBPassword"));
bld.Remove(0, bld.Length);
}
catch{}
}
}
 
Back
Top