using System;
using System.Runtime.Serialization;
using BLToolkit.Data.DataProvider;
namespace BLToolkit.Data
{
///
/// Defines the base class for the namespace exceptions.
///
///
/// This class is the base class for exceptions that may occur during
/// execution of the namespace members.
///
[Serializable]
public class DataException : System.Data.DataException
{
///
/// Initializes a new instance of the class.
///
///
/// This constructor initializes the
/// property of the new instance
/// to a system-supplied message that describes the error,
/// such as "BLToolkit Data error has occurred."
///
public DataException()
: base("A BLToolkit Data error has occurred.")
{
}
///
/// Initializes a new instance of the class
/// with the specified error message.
///
/// The message to display to the client when the
/// exception is thrown.
///
public DataException(string message)
: base(message)
{
}
///
/// Initializes a new instance of the class
/// with the specified error message and InnerException property.
///
/// The message to display to the client when the
/// exception is thrown.
/// The InnerException, if any, that threw
/// the current exception.
///
///
public DataException(string message, Exception innerException)
: base(message, innerException)
{
}
///
/// Initializes a new instance of the class
/// with the InnerException property.
///
/// The InnerException, if any, that threw
/// the current exception.
///
public DataException(Exception innerException)
: base(innerException.Message, innerException)
{
}
///
/// Initializes a new instance of the class
/// with serialized data.
///
/// The object that holds the serialized object data.
/// The contextual information about the source or
/// destination.
/// This constructor is called during deserialization to
/// reconstitute the exception object transmitted over a stream.
protected DataException(SerializationInfo info, StreamingContext context)
: base(info, context)
{
}
#region Internal
private readonly DbManager _dbManager;
static string GetMessage(DbManager dbManager, Exception innerException)
{
object obj = dbManager.DataProvider.Convert(
innerException, ConvertType.ExceptionToErrorMessage);
return obj is Exception ? ((Exception)obj).Message : obj.ToString();
}
internal DataException(DbManager dbManager, Exception innerException)
: this(GetMessage(dbManager, innerException), innerException)
{
_dbManager = dbManager;
}
#endregion
#region Public Properties
///
/// Gets a number that identifies the type of error.
///
public int? Number
{
get
{
return (int?)(_dbManager == null? null:
_dbManager.DataProvider.Convert(
InnerException, ConvertType.ExceptionToErrorNumber));
}
}
#endregion
}
}