Class OpenPdfException

All Implemented Interfaces:
Serializable

public class OpenPdfException extends OpenException
PDF Exception - Base exception for all PDF operations PDF 异常 - 所有 PDF 操作的基础异常

This exception is thrown when PDF operations fail, including parsing, writing, signing, and form processing errors. Extends OpenException to integrate with the OpenCode unified exception hierarchy.

当 PDF 操作失败时抛出此异常,包括解析、写入、签名和表单处理错误。 继承 OpenException 以集成 OpenCode 统一异常体系。

Features | 主要功能:

  • Operation type tracking - 操作类型跟踪
  • Page number association for page-specific errors - 页面相关错误的页码关联
  • Factory methods for common error scenarios - 常见错误场景的工厂方法
  • Error code support via OpenException - 通过 OpenException 支持错误码
  • Component name "PDF" auto-prefixed in messages - 消息中自动添加 "PDF" 组件前缀

Usage Examples | 使用示例:

throw OpenPdfException.invalidFormat("Missing header");
throw OpenPdfException.readFailed("/path/to/file.pdf", cause);
throw OpenPdfException.invalidPageNumber(5, 3);

Security | 安全性:

  • Thread-safe: Yes — immutable after construction - 线程安全: 是 — 构造后不可变
  • Null-safe: Partial — message is required, operation and pageNumber may be null - 空值安全: 部分 — 消息必填,操作和页码可为空
Since:
JDK 25, opencode-base-pdf V1.0.3
Author:
Leon Soo www.LeonSoo.com
See Also:
  • Constructor Details

    • OpenPdfException

      public OpenPdfException(String message)
      Creates exception with message 创建带消息的异常
      Parameters:
      message - error message | 错误消息
    • OpenPdfException

      public OpenPdfException(String message, Throwable cause)
      Creates exception with message and cause 创建带消息和原因的异常
      Parameters:
      message - error message | 错误消息
      cause - root cause | 根本原因
    • OpenPdfException

      public OpenPdfException(String operation, String message)
      Creates exception with operation and message 创建带操作和消息的异常
      Parameters:
      operation - operation type | 操作类型
      message - error message | 错误消息
    • OpenPdfException

      public OpenPdfException(String operation, String message, Throwable cause)
      Creates exception with operation, message and cause 创建带操作、消息和原因的异常
      Parameters:
      operation - operation type | 操作类型
      message - error message | 错误消息
      cause - root cause | 根本原因
    • OpenPdfException

      public OpenPdfException(String operation, int pageNumber, String message)
      Creates exception with operation, page number and message 创建带操作、页码和消息的异常
      Parameters:
      operation - operation type | 操作类型
      pageNumber - page number | 页码
      message - error message | 错误消息
  • Method Details

    • operation

      public String operation()
      Gets the operation type 获取操作类型
      Returns:
      operation type | 操作类型
    • pageNumber

      public Integer pageNumber()
      Gets the page number 获取页码
      Returns:
      page number, or null if not applicable | 页码,如不适用则返回 null
    • invalidFormat

      public static OpenPdfException invalidFormat(String reason)
      Creates exception for invalid PDF format 创建无效 PDF 格式异常
      Parameters:
      reason - reason description | 原因描述
      Returns:
      OpenPdfException
    • readFailed

      public static OpenPdfException readFailed(String path, Throwable cause)
      Creates exception for read failure 创建读取失败异常
      Parameters:
      path - file path | 文件路径
      cause - root cause | 根本原因
      Returns:
      OpenPdfException
    • writeFailed

      public static OpenPdfException writeFailed(String path, Throwable cause)
      Creates exception for write failure 创建写入失败异常
      Parameters:
      path - file path | 文件路径
      cause - root cause | 根本原因
      Returns:
      OpenPdfException
    • invalidPageNumber

      public static OpenPdfException invalidPageNumber(int pageNumber, int totalPages)
      Creates exception for invalid page number 创建无效页码异常
      Parameters:
      pageNumber - page number | 页码
      totalPages - total pages in document | 文档总页数
      Returns:
      OpenPdfException
    • passwordRequired

      public static OpenPdfException passwordRequired()
      Creates exception for password required 创建需要密码异常
      Returns:
      OpenPdfException
    • wrongPassword

      public static OpenPdfException wrongPassword()
      Creates exception for wrong password 创建密码错误异常
      Returns:
      OpenPdfException
    • signatureFailed

      public static OpenPdfException signatureFailed(String reason, Throwable cause)
      Creates exception for signature failure 创建签名失败异常
      Parameters:
      reason - reason description | 原因描述
      cause - root cause | 根本原因
      Returns:
      OpenPdfException
    • fieldNotFound

      public static OpenPdfException fieldNotFound(String fieldName)
      Creates exception for form field not found 创建表单字段未找到异常
      Parameters:
      fieldName - field name | 字段名
      Returns:
      OpenPdfException
    • unsupportedFeature

      public static OpenPdfException unsupportedFeature(String feature)
      Creates exception for unsupported feature 创建不支持功能异常
      Parameters:
      feature - feature name | 功能名称
      Returns:
      OpenPdfException
    • mergeFailed

      public static OpenPdfException mergeFailed(String reason, Throwable cause)
      Creates exception for merge failure 创建合并失败异常
      Parameters:
      reason - reason description | 原因描述
      cause - root cause | 根本原因
      Returns:
      OpenPdfException
    • splitFailed

      public static OpenPdfException splitFailed(String reason, Throwable cause)
      Creates exception for split failure 创建拆分失败异常
      Parameters:
      reason - reason description | 原因描述
      cause - root cause | 根本原因
      Returns:
      OpenPdfException