> ## Documentation Index
> Fetch the complete documentation index at: https://docs.syntblaze.com/llms.txt
> Use this file to discover all available pages before exploring further.

# Swift Rethrowing Method

A rethrowing method or function in Swift, designated by the `rethrows` declaration modifier, is a higher-order function that propagates errors exclusively from its throwing closure parameters. It guarantees to the compiler that the function itself will only throw an error if at least one of the closures passed to it as an argument throws an error.

## Syntax

```swift theme={"dark"}
func performAction(closure: () throws -> Void) rethrows {
    try closure()
}
```

## Call Site Evaluation

The Swift compiler evaluates `rethrows` statically at the call site based on the type signature of the provided closure:

* **Non-Throwing Argument:** If the passed closure does not throw, the compiler treats the rethrowing function as a non-throwing function. The `try` keyword is not required at the call site.
* **Throwing Argument:** If the passed closure can throw, the compiler treats the rethrowing function as a throwing function. The call site must be prefixed with `try`, `try?`, or `try!`:
  * `try` requires the error to be handled within the calling scope (e.g., via a `do-catch` block or by propagating it further).
  * `try?` handles the error inline by returning an Optional `nil` if an error occurs, bypassing the need for scope-level handling.
  * `try!` intentionally bypasses error handling entirely, forcing the execution and crashing the program if an error is thrown.

```swift theme={"dark"}
enum CustomError: Error {
    case operationFailed
    case transformedError
}

// Non-throwing closure passed: No 'try' needed
performAction {
    print("Safe execution")
}

// Throwing closure passed: 'try' is required
do {
    try performAction {
        throw CustomError.operationFailed
    }
} catch {
    print(error)
}
```

## Architectural Constraints

1. **Parameter Requirement:** A function declared with `rethrows` must accept at least one throwing parameter (typically a closure marked with `throws`).
2. **Internal Error Generation:** A rethrowing function cannot synthesize and throw its own independent errors. It is strictly prohibited from using the `throw` keyword to throw an error that does not originate from its throwing parameters.
3. **Error Transformation:** A rethrowing function is permitted to catch an error emitted by its throwing parameter and throw a *different* error in its place. The compiler recognizes this as satisfying the `rethrows` contract because the initial failure originated from the parameter.

```swift theme={"dark"}
func transformError(closure: () throws -> Void) rethrows {
    do {
        try closure()
    } catch {
        // Permitted: Throwing a new error strictly in response to the closure's error
        throw CustomError.transformedError
    }
}
```

## Protocol Conformance and Overriding

In Swift, `rethrows` is a declaration modifier, not a distinct function type. Referencing a `rethrows` function as a value yields a standard `throws` function type. However, at the declaration level, the compiler enforces specific inheritance, overriding, and protocol conformance rules based on error-throwing capabilities:

* A `rethrows` method declaration can satisfy a protocol requirement for a `throws` method.
* A non-throwing method declaration can satisfy a protocol requirement for a `rethrows` method.
* A `throws` method declaration **cannot** satisfy a protocol requirement for a `rethrows` method.
* A method overriding a `rethrows` method can be declared as either `rethrows` or non-throwing, but cannot be declared as `throws`.

<div
  style={{ 
display: "flex", 
justifyContent: "space-between", 
alignItems: "center", 
maxWidth: "754px", 
padding: "1rem 0",
marginBottom: "24px"
}}
>
  <span style={{ fontWeight: "bold", fontSize: "1.25rem", color: "var(--tw-prose-headings)", fontFamily: "Inter, ui-sans-serif, system-ui, sans-serif" }}>Tired of Poor Swift Skills? Fix That With Deep Grasping!</span>

  <a
    href="https://syntblaze.com"
    target="_blank"
    style={{ 
  marginLeft: "24px",
  textDecoration: "none", 
  backgroundColor: "#007AFF",
  color: "#ffffff", 
  padding: "6px 16px", 
  borderRadius: "16px",
  fontSize: "0.9rem",
  fontWeight: "600",
  textAlign: "center",
  transition: "background-color 0.2s ease"
}}
  >
    Learn More
  </a>
</div>

<div style={{ display: "flex", gap: "12px", flexWrap: "wrap" }}>
  <img src="https://mintcdn.com/syntblazellc/-L0ums_2lctDSZ1l/images/skill-tracking.png?fit=max&auto=format&n=-L0ums_2lctDSZ1l&q=85&s=b9b0305c93bb501c9e767b5c76c88835" style={{ width: "30%", minWidth: 60 }} width="621" height="1344" data-path="images/skill-tracking.png" />

  <img src="https://mintcdn.com/syntblazellc/23tyuOzaWS88qFlc/images/nuggets.png?fit=max&auto=format&n=23tyuOzaWS88qFlc&q=85&s=c86c80197299762989e9b882419b2109" style={{ width: "30%", minWidth: 60 }} width="621" height="1344" data-path="images/nuggets.png" />

  <img src="https://mintcdn.com/syntblazellc/-L0ums_2lctDSZ1l/images/bite-sized-exercises.png?fit=max&auto=format&n=-L0ums_2lctDSZ1l&q=85&s=a65f9a38c37ff28ab73ed783c53c60e3" style={{ width: "30%", minWidth: 60 }} width="621" height="1344" data-path="images/bite-sized-exercises.png" />
</div>

<div style={{ display: "flex", gap: "12px", flexWrap: "wrap", marginTop: "12px" }}>
  <img src="https://mintcdn.com/syntblazellc/-L0ums_2lctDSZ1l/images/mastery-chain.png?fit=max&auto=format&n=-L0ums_2lctDSZ1l&q=85&s=748a1763454713e679260fbb95f154a2" style={{ width: "30%", minWidth: 60 }} width="621" height="1344" data-path="images/mastery-chain.png" />

  <img src="https://mintcdn.com/syntblazellc/-L0ums_2lctDSZ1l/images/element-previews.png?fit=max&auto=format&n=-L0ums_2lctDSZ1l&q=85&s=242f61448ff5dd6deaaab2dccc13b507" style={{ width: "30%", minWidth: 60 }} width="621" height="1344" data-path="images/element-previews.png" />

  <img src="https://mintcdn.com/syntblazellc/-L0ums_2lctDSZ1l/images/element-explanations.png?fit=max&auto=format&n=-L0ums_2lctDSZ1l&q=85&s=cf0fc1c31f9cd0fc26716781be05fbc9" style={{ width: "30%", minWidth: 60 }} width="621" height="1344" data-path="images/element-explanations.png" />
</div>
