org.firebirdsql.util

## Class SQLExceptionChainBuilder<E extends java.sql.SQLException>

- java.lang.Object
- - org.firebirdsql.util.SQLExceptionChainBuilder<E>

- Type Parameters:
    `E` - type of SQLException (definition: `E extends SQLException`)

      @InternalApi
      public final class SQLExceptionChainBuilder<E extends java.sql.SQLException>
      extends java.lang.Object

  Helper class for building `SQLException` chains.

  NOTE: This class is not thread-safe; an instance should only be used on a single thread or with proper external synchronisation.

  Since:
    2.2
  Author:
    Mark Rotteveel

- - ### Constructor Summary

    Constructors
    Constructor and Description
    `SQLExceptionChainBuilder()` Create SQLExceptionChainBuilder
    `SQLExceptionChainBuilder(E root)` Create SQLExceptionChainBuilder with the specified root exception.

  - ### Method Summary

    All Methods Instance Methods Concrete Methods
    Modifier and Type | Method and Description
    --- | ---
    `SQLExceptionChainBuilder<E>` | `addFirst(E sqle)` Adds the passed SQLException as the first exception in the chain.
    `SQLExceptionChainBuilder<E>` | `append(E sqle)` Appends the passed SQLException to the exception chain.
    `E` | `getException()`
    `boolean` | `hasException()`
    `java.util.Optional<java.sql.SQLException>` | `optException()`
    `void` | `throwIfPresent()` Throws the root SQLException stored in the chain, if present; otherwise does nothing.

    - ### Methods inherited from class java.lang.Object

      `clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

- - ### Constructor Detail

    - #### SQLExceptionChainBuilder

          public SQLExceptionChainBuilder()

      Create SQLExceptionChainBuilder

    - #### SQLExceptionChainBuilder

          public SQLExceptionChainBuilder(E root)

      Create SQLExceptionChainBuilder with the specified root exception.
      Parameters:
        `root` - root SQLException

  - ### Method Detail

    - #### append

          public SQLExceptionChainBuilder<E> append(E sqle)

      Appends the passed SQLException to the exception chain.

      If this SQLExceptionChainBuilder does not have a root, `sqle` will be come the root.

      Parameters:
        `sqle` - SQLException to add to the chain.
      Returns:
        this SQLExceptionChainBuilder

    - #### addFirst

          public SQLExceptionChainBuilder<E> addFirst(E sqle)

      Adds the passed SQLException as the first exception in the chain.

      If this SQLExceptionChainBuilder already has a root, that root will be chained to `sqle`, and `sqle` becomes the new root.

      Parameters:
        `sqle` - SQLException to add to the chain
      Returns:
        this SQLExceptionChainBuilder
      Since:
        5

    - #### hasException

          public boolean hasException()

      Returns:
        `true` if this SQLExceptionChainBuilder contains at least one SQLException.

    - #### getException

          public E getException()

      Returns:
        the root SQLException or `null` if no SQLException was added to this SQLExceptionChainBuilder

    - #### optException

          public java.util.Optional<java.sql.SQLException> optException()

      Returns:
        the root SQLException or empty if no SQLException was added to this SQLExceptionChainBuilder
      Since:
        5.0.7

    - #### throwIfPresent

          public void throwIfPresent()
                              throws java.sql.SQLException

      Throws the root SQLException stored in the chain, if present; otherwise does nothing.
      Throws:
        `java.sql.SQLException` - the root SQLException in this chain builder
      Since:
        5.0.7

Copyright © 2001-2025 Jaybird (Firebird JDBC) team. All rights reserved.