UserFriendlyException.cs 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124
  1. using System;
  2. using System.Runtime.Serialization;
  3. using Abp.Logging;
  4. namespace Abp.UI
  5. {
  6. /// <summary>
  7. /// This exception type is directly shown to the user.
  8. /// </summary>
  9. [Serializable]
  10. public class UserFriendlyException : AbpException, IHasLogSeverity, IHasErrorCode
  11. {
  12. /// <summary>
  13. /// Additional information about the exception.
  14. /// </summary>
  15. public string Details { get; private set; }
  16. /// <summary>
  17. /// An arbitrary error code.
  18. /// </summary>
  19. public int Code { get; set; }
  20. /// <summary>
  21. /// Severity of the exception.
  22. /// Default: Warn.
  23. /// </summary>
  24. public LogSeverity Severity { get; set; }
  25. /// <summary>
  26. /// Constructor.
  27. /// </summary>
  28. public UserFriendlyException()
  29. {
  30. Severity = LogSeverity.Warn;
  31. }
  32. /// <summary>
  33. /// Constructor for serializing.
  34. /// </summary>
  35. public UserFriendlyException(SerializationInfo serializationInfo, StreamingContext context)
  36. : base(serializationInfo, context)
  37. {
  38. }
  39. /// <summary>
  40. /// Constructor.
  41. /// </summary>
  42. /// <param name="message">Exception message</param>
  43. public UserFriendlyException(string message)
  44. : base(message)
  45. {
  46. Severity = LogSeverity.Warn;
  47. }
  48. /// <summary>
  49. /// Constructor.
  50. /// </summary>
  51. /// <param name="message">Exception message</param>
  52. /// <param name="severity">Exception severity</param>
  53. public UserFriendlyException(string message, LogSeverity severity)
  54. : base(message)
  55. {
  56. Severity = severity;
  57. }
  58. /// <summary>
  59. /// Constructor.
  60. /// </summary>
  61. /// <param name="code">Error code</param>
  62. /// <param name="message">Exception message</param>
  63. public UserFriendlyException(int code, string message)
  64. : this(message)
  65. {
  66. Code = code;
  67. }
  68. /// <summary>
  69. /// Constructor.
  70. /// </summary>
  71. /// <param name="message">Exception message</param>
  72. /// <param name="details">Additional information about the exception</param>
  73. public UserFriendlyException(string message, string details)
  74. : this(message)
  75. {
  76. Details = details;
  77. }
  78. /// <summary>
  79. /// Constructor.
  80. /// </summary>
  81. /// <param name="code">Error code</param>
  82. /// <param name="message">Exception message</param>
  83. /// <param name="details">Additional information about the exception</param>
  84. public UserFriendlyException(int code, string message, string details)
  85. : this(message, details)
  86. {
  87. Code = code;
  88. }
  89. /// <summary>
  90. /// Constructor.
  91. /// </summary>
  92. /// <param name="message">Exception message</param>
  93. /// <param name="innerException">Inner exception</param>
  94. public UserFriendlyException(string message, Exception innerException)
  95. : base(message, innerException)
  96. {
  97. Severity = LogSeverity.Warn;
  98. }
  99. /// <summary>
  100. /// Constructor.
  101. /// </summary>
  102. /// <param name="message">Exception message</param>
  103. /// <param name="details">Additional information about the exception</param>
  104. /// <param name="innerException">Inner exception</param>
  105. public UserFriendlyException(string message, string details, Exception innerException)
  106. : this(message, innerException)
  107. {
  108. Details = details;
  109. }
  110. }
  111. }