CustomException.cs 1.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  1. using System;
  2. namespace Infrastructure
  3. {
  4. public class CustomException : Exception
  5. {
  6. public int Code { get; set; }
  7. /// <summary>
  8. /// 前端提示语
  9. /// </summary>
  10. public string Msg { get; set; }
  11. /// <summary>
  12. /// 记录到日志的详细内容
  13. /// </summary>
  14. public string LogMsg { get; set; }
  15. /// <summary>
  16. /// 是否通知
  17. /// </summary>
  18. public bool Notice { get; set; } = true;
  19. public CustomException(string msg) : base(msg)
  20. {
  21. }
  22. public CustomException(int code, string msg) : base(msg)
  23. {
  24. Code = code;
  25. Msg = msg;
  26. }
  27. public CustomException(ResultCode resultCode, string msg, bool notice = true) : base(msg)
  28. {
  29. Code = (int)resultCode;
  30. Notice = notice;
  31. }
  32. /// <summary>
  33. /// 自定义异常
  34. /// </summary>
  35. /// <param name="resultCode"></param>
  36. /// <param name="msg"></param>
  37. /// <param name="errorMsg">用于记录详细日志到输出介质</param>
  38. public CustomException(ResultCode resultCode, string msg, object errorMsg) : base(msg)
  39. {
  40. Code = (int)resultCode;
  41. LogMsg = errorMsg.ToString();
  42. }
  43. }
  44. }