2026-06-01 13:42:40 +08:00
|
|
|
namespace QYZH.InteractiveMagazine.Models.Common;
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// 业务异常类
|
|
|
|
|
/// </summary>
|
|
|
|
|
public class BusinessException : Exception
|
|
|
|
|
{
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// 错误码
|
|
|
|
|
/// </summary>
|
|
|
|
|
public int Code { get; set; }
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// 无参构造函数
|
|
|
|
|
/// </summary>
|
|
|
|
|
public BusinessException() : base()
|
|
|
|
|
{
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// 构造函数
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="message">异常消息</param>
|
|
|
|
|
public BusinessException(string message) : base(message)
|
|
|
|
|
{
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// 构造函数
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="message">异常消息</param>
|
|
|
|
|
/// <param name="code">错误码</param>
|
|
|
|
|
public BusinessException(string message, int code) : base(message)
|
|
|
|
|
{
|
|
|
|
|
Code = code;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// 构造函数
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="message">异常消息</param>
|
|
|
|
|
/// <param name="innerException">内部异常</param>
|
|
|
|
|
public BusinessException(string message, Exception innerException) : base(message, innerException)
|
|
|
|
|
{
|
|
|
|
|
}
|
2026-06-11 17:01:24 +08:00
|
|
|
|
|
|
|
|
public static void ThrowIf(bool isTrue, string message)
|
|
|
|
|
{
|
|
|
|
|
if (isTrue) throw new BusinessException(message);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public static void ThrowIf(bool isTrue, Func<string> action)
|
|
|
|
|
{
|
|
|
|
|
if (isTrue) throw new BusinessException(action.Invoke());
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public static void ThrowIf(bool isTrue, string message, Action action)
|
|
|
|
|
{
|
|
|
|
|
if (isTrue)
|
|
|
|
|
{
|
|
|
|
|
action();
|
|
|
|
|
throw new BusinessException(message);
|
|
|
|
|
}
|
|
|
|
|
}
|
2026-06-01 13:42:40 +08:00
|
|
|
}
|