# Rethrows in method of struct with a throwing property

**URL:** <https://forums.swift.org/t/rethrows-in-method-of-struct-with-a-throwing-property/39489>\
**Category:** Using Swift\
**Created:** [August 18, 2020, 4:38pm UTC](https://forums.swift.org/t/rethrows-in-method-of-struct-with-a-throwing-property/39489 "2020-08-18T16:38:19Z")\
**Posts on this page:** 1\
**Showing post:** 9

<div class="post-metadata">

**Author:** ![anon9791410](https://avatars.discourse-cdn.com/v4/letter/a/9fc348/32.png) [@anon9791410](https://forums.swift.org/u/anon9791410)\
**Post date:** [August 19, 2020, 9:55pm UTC](https://forums.swift.org/t/rethrows-in-method-of-struct-with-a-throwing-property/39489/9 "2020-08-19T21:55:41Z")

</div>

You might be able to use overloading, [as is necessary for your problem when it comes to functions](https://forums.swift.org/t/reference-default-comparison-function-as-a-function-parameter/34654/7).

It is terrible, yes, but I can't think of a way to avoid copying everything that uses one of the two closure options. I think a generic type is better than two manual concrete types if there's other common functionality that doesn't rely on the closure.

```swift
struct Foo<Closure> {
  private let closure: Closure
}

```

```swift
extension Foo where Closure == () -> Void {
  init(_ closure: Closure) {
    self.closure = closure
  }

  func callAsFunction() {
    closure()
  }
}

```

```swift
extension Foo where Closure == () throws -> Void {
  init(_ closure: Closure) {
    self.closure = closure
  }

  func callAsFunction() throws {
    try closure()
  }
}

```

```swift
let foo1 = Foo { print("Foo") }
foo1()

let foo2 = Foo {
  struct Error: Swift.Error { }
  throw Error()
}

do {
  try foo2()
} catch {
  print("Error")
}

```

---

_[View the full topic](https://forums.swift.org/t/rethrows-in-method-of-struct-with-a-throwing-property/39489)._
