using NTwain.Data; using System; using System.Runtime.Serialization; using System.Security.Permissions; namespace NTwain { /// /// Represents a general exception with TWAIN. /// [Serializable] public class TwainException : Exception { /// /// Initializes a new instance of the class. /// public TwainException() { } /// /// Initializes a new instance of the class. /// /// The return code. /// The message. public TwainException(ReturnCode returnCode, string message) : this(returnCode, message, null) { } /// /// Initializes a new instance of the class. /// /// The return code. /// The message. /// The inner exception. public TwainException(ReturnCode returnCode, string message, Exception innerException) : base(message, innerException) { ReturnCode = returnCode; } /// /// Initializes a new instance of the class. /// /// The that holds the serialized object data about the exception being thrown. /// The that contains contextual information about the source or destination. /// /// The parameter is null. /// /// /// The class name is null or is zero (0). /// protected TwainException(SerializationInfo info, StreamingContext context) : base(info, context) { if (info != null) { ReturnCode = (ReturnCode)info.GetUInt16("RC"); } } /// /// When overridden in a derived class, sets the with information about the exception. /// /// The that holds the serialized object data about the exception being thrown. /// The that contains contextual information about the source or destination. /// /// The parameter is a null reference (Nothing in Visual Basic). /// /// /// /// /// [SecurityPermissionAttribute(SecurityAction.Demand, SerializationFormatter = true)] public override void GetObjectData(SerializationInfo info, StreamingContext context) { if (info != null) { info.AddValue("RC", ReturnCode); } base.GetObjectData(info, context); } /// /// Gets the return code from the TWAIN operation if applicable. /// /// /// The return code. /// public ReturnCode ReturnCode { get; private set; } } }