Class OpenBizException

All Implemented Interfaces:
OpenExceptionMeta, Serializable

public class OpenBizException extends OpenWebException
Open Business Exception 业务异常

Exception for business logic errors.

业务逻辑错误的异常。

Features | 主要功能:

  • Business error with attached data - 带附加数据的业务错误
  • Factory methods for common business errors - 常见业务错误的工厂方法
  • Extends OpenWebException with data payload - 扩展 OpenWebException 并携带数据负载
  • ResultCode integration - ResultCode 集成

Usage Examples | 使用示例:

// Using factory methods
throw OpenBizException.dataNotFound("User not found");
throw OpenBizException.dataDuplicate("Email already exists");
throw OpenBizException.validationError("Invalid input", errors);

// With result code
throw new OpenBizException(CommonResultCode.BUSINESS_ERROR);

Security | 安全性:

  • Thread-safe: Yes (immutable fields) - 线程安全: 是(不可变字段)
  • Null-safe: No (message should not be null) - 空值安全: 否(消息不应为 null)
Since:
JDK 25, opencode-base-web V1.0.0
Author:
Leon Soo www.LeonSoo.com
See Also:
  • Constructor Details

    • OpenBizException

      public OpenBizException(String message)
      Create exception with message 使用消息创建异常
      Parameters:
      message - the message | 消息
    • OpenBizException

      public OpenBizException(String code, String message)
      Create exception with code and message 使用代码和消息创建异常
      Parameters:
      code - the code | 代码
      message - the message | 消息
    • OpenBizException

      public OpenBizException(ResultCode resultCode)
      Create exception with result code 使用响应码创建异常
      Parameters:
      resultCode - the result code | 响应码
    • OpenBizException

      public OpenBizException(ResultCode resultCode, String message)
      Create exception with result code and custom message 使用响应码和自定义消息创建异常
      Parameters:
      resultCode - the result code | 响应码
      message - the custom message | 自定义消息
    • OpenBizException

      public OpenBizException(ResultCode resultCode, Object data)
      Create exception with result code and data 使用响应码和数据创建异常
      Parameters:
      resultCode - the result code | 响应码
      data - the data | 数据
    • OpenBizException

      public OpenBizException(String code, String message, Object data)
      Create exception with code, message and data 使用代码、消息和数据创建异常
      Parameters:
      code - the code | 代码
      message - the message | 消息
      data - the data | 数据
    • OpenBizException

      public OpenBizException(String message, Throwable cause)
      Create exception with message and cause 使用消息和原因创建异常
      Parameters:
      message - the message | 消息
      cause - the cause | 原因
    • OpenBizException

      public OpenBizException(ResultCode resultCode, Throwable cause)
      Create exception with result code and cause 使用响应码和原因创建异常
      Parameters:
      resultCode - the result code | 响应码
      cause - the cause | 原因
  • Method Details

    • getData

      public Object getData()
      Get the data 获取数据
      Returns:
      the data | 数据
    • dataNotFound

      public static OpenBizException dataNotFound(String message)
      Create data not found exception 创建数据不存在异常
      Parameters:
      message - the message | 消息
      Returns:
      the exception | 异常
    • dataDuplicate

      public static OpenBizException dataDuplicate(String message)
      Create data duplicate exception 创建数据重复异常
      Parameters:
      message - the message | 消息
      Returns:
      the exception | 异常
    • operationFailed

      public static OpenBizException operationFailed(String message)
      Create operation failed exception 创建操作失败异常
      Parameters:
      message - the message | 消息
      Returns:
      the exception | 异常
    • validationError

      public static OpenBizException validationError(String message)
      Create validation error exception 创建验证错误异常
      Parameters:
      message - the message | 消息
      Returns:
      the exception | 异常
    • validationError

      public static OpenBizException validationError(String message, Object errors)
      Create validation error exception with data 创建带数据的验证错误异常
      Parameters:
      message - the message | 消息
      errors - the validation errors | 验证错误
      Returns:
      the exception | 异常