Package: org.apache.groovy.contracts

## [Java] Class ThrowsIfSupport

- org.apache.groovy.contracts.ThrowsIfSupport

-     public final class ThrowsIfSupport
      extends Object

  Runtime support for `checked` `@ThrowsIf` arm-sets (invoked from generated code; not intended to be called by user code). The checks report a broken contract implementation as a ThrowsIfViolation — never as the arm's declared exception, which is defined behaviour delivered at method entry.

  Since:
    6.0.0
  See Also:
    ThrowsIfViolation

- - ### Methods Summary

    Methods
    Type Params | Return Type | Name and description
    --- | --- | ---
    `` | `public static void` | `mustThrow(boolean[] held, String[] conditions)` The must-throw check, run when the method body completes normally: no unwoven arm's condition may have held on entry (a woven arm's guard makes this unreachable for that arm by construction).
    `` | `public static Throwable` | `onlyWhen(Throwable thrown, boolean[] held, Class<?>[] types, String[] conditions, boolean exhaustive)` The only-when check, run when the method body throws: a throwable matching some arm's exception type must be justified by some matching arm's condition having held on entry.

  - ### Inherited Methods Summary

    Inherited Methods
    Methods inherited from class | Name
    --- | ---
    `class Object` | `equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

- - ### Method Detail

    - #### public static void mustThrow(boolean[] held, String[] conditions)

      The must-throw check, run when the method body completes normally: no unwoven arm's condition may have held on entry (a woven arm's guard makes this unreachable for that arm by construction).

      throws:
        ThrowsIfViolation when some condition held and the method nevertheless returned
      Parameters:
        `held` - per-unwoven-arm: whether the arm's condition held on entry
        `conditions` - per-unwoven-arm: the arm's condition text (for the violation message)

    - #### public static Throwable onlyWhen(Throwable thrown, boolean[] held, Class<?>[] types, String[] conditions, boolean exhaustive)

      The only-when check, run when the method body throws: a throwable matching some arm's exception type must be justified by some matching arm's condition having held on entry. A justified (or unmatched, or non-`exhaustive`) throwable is returned for rethrow — defined behaviour propagates untouched.

      VirtualMachineErrors (`OutOfMemoryError`, `StackOverflowError`, ...) are never judged, whatever the arm types: a VM resource condition is outside contract semantics — no `@ThrowsIf` claim, however `exhaustive`, reasons about it — so it always propagates untouched.

      throws:
        ThrowsIfViolation when `thrown` matches an arm's type but no matching arm's condition held
      Parameters:
        `thrown` - the throwable escaping the method body
        `held` - per-arm: whether the arm's condition held on entry
        `types` - per-arm: the arm's declared exception type
        `conditions` - per-arm: the arm's condition text (for the violation message)
        `exhaustive` - whether the whole arm-set claims exhaustiveness (an iff); one-directional arm-sets are never only-when checked
      Returns:
        `thrown`, for rethrow, when it is in-contract