OracleException behavior
Posted: Tue 06 May 2014 12:22
The behavior of OracleException is inconsistent with that of SqlException. The OracleException's Errors property can be null, whereas the SqlException's one can never be null and always contains at least one entry. Moreover, SqlException.Message comprises all the messages from the Errors collection (separated with a new line), which OracleException doesn't:
This differences can lead to hidden bugs when implementing error handling involving OracleException by persons who are familiar with "handling" SqlException (which actually doesn't require any special handling for bringing up all the messages, in opposite to OracleException).
So please consider making OracleException's behavior to be consistent with that of SqlException. Note, if message concatenation will be implemented, that only distinct messages should be taken, in order to suppress duplicating messages for different data rows (like when multiple constraint checks fail upon closing OracleLoader).
Code: Select all
public SqlErrorCollection Errors
{
get
{
if (this._errors == null)
this._errors = new SqlErrorCollection();
return this._errors;
}
}
static SqlException CreateException(SqlErrorCollection errorCollection, ...)
{
var stringBuilder = new StringBuilder();
for (int index = 0; index < errorCollection.Count; ++index)
{
if (index > 0) stringBuilder.Append(Environment.NewLine);
stringBuilder.Append(errorCollection[index].Message);
}
... ...
return new SqlException(((object) stringBuilder).ToString(), ...);
}
So please consider making OracleException's behavior to be consistent with that of SqlException. Note, if message concatenation will be implemented, that only distinct messages should be taken, in order to suppress duplicating messages for different data rows (like when multiple constraint checks fail upon closing OracleLoader).