using System; using System.Diagnostics.CodeAnalysis; using System.Runtime.Serialization; namespace AMWD.Protocols.Modbus.Common { /// /// Represents errors that occurr during Modbus requests. /// [ExcludeFromCodeCoverage] public class ModbusException : Exception { /// /// Initializes a new instance of the class. /// public ModbusException() : base() { } /// /// Initializes a new instance of the class /// with a specified error message. /// /// The message that describes the error. public ModbusException(string message) : base(message) { } /// /// Initializes a new instance of the class /// with a specified error message and a reference to the inner exception /// that is the cause of this exception. /// /// The message that describes the error. /// /// The exception that is the cause of the current exception, /// or a null reference if no inner exception is specified. /// public ModbusException(string message, Exception innerException) : base(message, innerException) { } #if !NET8_0_OR_GREATER /// /// Initializes a new instance of the class /// with serialized data. /// /// /// The that holds the serialized /// object data about the exception being thrown. /// /// /// The that contains contextual /// information about the source or destination. /// protected ModbusException(SerializationInfo info, StreamingContext context) : base(info, context) { } #endif /// /// Gets the Modubs error code. /// #if NET6_0_OR_GREATER public ModbusErrorCode ErrorCode { get; init; } #else public ModbusErrorCode ErrorCode { get; set; } #endif /// /// Gets the Modbus error message. /// public string ErrorMessage => ErrorCode.GetDescription(); } }