Module org.firebirdsql.jaybird
Package org.firebirdsql.jaybird.util

# Class SQLExceptionChainBuilder

java.lang.Object
org.firebirdsql.jaybird.util.SQLExceptionChainBuilder

@NullMarked public final class SQLExceptionChainBuilder extends 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
Description
`SQLExceptionChainBuilder()`

## Method Summary

Modifier and Type
Method
Description
`SQLExceptionChainBuilder`
`addFirst(SQLException sqle)`
Adds the passed SQLException as the first exception in the chain.
`SQLExceptionChainBuilder`
`append(SQLException sqle)`
Appends the passed SQLException to the exception chain.
`@Nullable SQLException`
`getException()`
`boolean`
`hasException()`
`@NonNull Optional<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 Details

### SQLExceptionChainBuilder

public SQLExceptionChainBuilder()

## Method Details

### append

public SQLExceptionChainBuilder append(SQLException 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 addFirst(SQLException 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 @Nullable SQLException getException()

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

### optException

public @NonNull Optional<SQLException> optException()

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

### throwIfPresent

public void throwIfPresent() throws SQLException
Throws the root SQLException stored in the chain, if present; otherwise does nothing.

Throws:
  `SQLException` - the root SQLException in this chain builder
Since:
  6