PlcException.cs 1.1 KB

123456789101112131415161718192021222324252627282930313233343536373839
  1. using System;
  2. namespace S7.Net
  3. {
  4. #if NET_FULL
  5. [Serializable]
  6. #endif
  7. public class PlcException : Exception
  8. {
  9. public ErrorCode ErrorCode { get; }
  10. public PlcException(ErrorCode errorCode) : this(errorCode, $"PLC communication failed with error '{errorCode}'.")
  11. {
  12. }
  13. public PlcException(ErrorCode errorCode, Exception innerException) : this(errorCode, innerException.Message,
  14. innerException)
  15. {
  16. }
  17. public PlcException(ErrorCode errorCode, string message) : base(message)
  18. {
  19. ErrorCode = errorCode;
  20. }
  21. public PlcException(ErrorCode errorCode, string message, Exception inner) : base(message, inner)
  22. {
  23. ErrorCode = errorCode;
  24. }
  25. #if NET_FULL
  26. protected PlcException(System.Runtime.Serialization.SerializationInfo info,
  27. System.Runtime.Serialization.StreamingContext context) : base(info, context)
  28. {
  29. ErrorCode = (ErrorCode) info.GetInt32(nameof(ErrorCode));
  30. }
  31. #endif
  32. }
  33. }