# 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:** 4

<div class="post-metadata">

**Author:** ![Nickolas\_Pohilets](https://sea2.discourse-cdn.com/swift/user_avatar/forums.swift.org/nickolas_pohilets/32/10659_2.png) [@Nickolas\_Pohilets](https://forums.swift.org/u/Nickolas_Pohilets)\
**Post date:** [August 19, 2020, 9:42am UTC](https://forums.swift.org/t/rethrows-in-method-of-struct-with-a-throwing-property/39489/4 "2020-08-19T09:42:05Z")

</div>

> [@jrose](#):
>
> No, there isn't. Since you could have a `var foo: Foo` , the throwing-ness would have to show up in the type of the struct somehow, so that you can't accidentally copy a throwing-Foo into a non-throwing-Foo. But there's not a way to do that today (and no obvious way to add it to the language).

There were some discussions about typed `throws`:

- [Typed throw functions](https://forums.swift.org/t/typed-throw-functions/38860)
- [[Discussion] Analysis of the design of typed throws](https://forums.swift.org/t/discussion-analysis-of-the-design-of-typed-throws/5301)
- [[Pitch] Typed throws](https://forums.swift.org/t/pitch-typed-throws/5233)  
and more.

With types throws, you could use generics:

```swift
struct Foo<E: any Error> {
    let maybeThrowing: () throws E -> ()
    
    init(_ maybeThrowing: () throws E -> ()) {
        self.maybeThrowing = maybeThrowing
    }

    func bar() throws E {
        try maybeThrowing()
    }
}

var foo1 = Foo { print("Foo") } // Foo<Never>
foo1.bar()

let foo2 = Foo { throw Error() } // Foo<Error>

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

foo1 = foo2 // error: Cannot assign value of Foo<Error> to variable of type Foo<Never>

```

Also note that existential type `Error` (aka `any Error`) does not conform to `Error`. So  
for the `Foo<Error>` to work, we would need another feature, which is not yet implemented - [Existential subtyping as generic constraint](https://forums.swift.org/t/existential-subtyping-as-generic-constraint/31584).

---

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