MirlvsMaximvs
MirlvsMaximvs

Reputation: 1483

One Exception Two Messages

When I get an exception in this code, I don't know why the exception message appears twice. I'll try explain it better: a picture is worth a thousand words:

enter image description here

can Anyone help me?

Thanks in adavance!

Upvotes: 1

Views: 723

Answers (1)

C.Evenhuis
C.Evenhuis

Reputation: 26446

In the image you can see the newline between the Exception message. In the OdbcConnection class, the CreateException() method processes a OdbcErrorCollection of errors, and glues them together with a Environment.NewLine (code from .NET 4.0 System.Data):

internal static OdbcException CreateException(OdbcErrorCollection errors, ODBC32.RetCode retcode)
{
  StringBuilder stringBuilder = new StringBuilder();
  foreach (OdbcError odbcError in errors)
  {
    if (stringBuilder.Length > 0)
      stringBuilder.Append(Environment.NewLine);
    stringBuilder.Append(Res.GetString("Odbc_ExceptionMessage", (object) ODBC32.RetcodeToString(retcode), (object) odbcError.SQLState, (object) odbcError.Message));
  }
  return new OdbcException(((object) stringBuilder).ToString(), errors);
}

Apparently the underlying library runs into the same error twice, and then throws the (one) exception to you.

I don't know if there is anything you can do to prevent this, it doesn't seem like there's anything wrong with your code.

Upvotes: 3

Related Questions