# Throwing subscript setters

**URL:** <https://forums.swift.org/t/throwing-subscript-setters/73224>\
**Category:** Discussion\
**Tags:** throw, subscripts\
**Created:** [July 17, 2024, 5:32am UTC](https://forums.swift.org/t/throwing-subscript-setters/73224 "2024-07-17T05:32:27Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![tera](https://sea2.discourse-cdn.com/swift/user_avatar/forums.swift.org/tera/32/38201_2.png) [@tera](https://forums.swift.org/u/tera)\
**Post date:** [July 17, 2024, 5:32am UTC](https://forums.swift.org/t/throwing-subscript-setters/73224/1 "2024-07-17T05:32:27Z")

</div>

What is the reason behind prohibiting throwing subscript setters?

```swift
struct S {
    subscript(c c: Int) -> Int {
        get { 0 }
        set throws {} // 🛑
    }
    subscript(d d: Int) -> Int {
        get throws { 0 }
        set throws {} // 🛑
    }
}

```

---

<div class="post-metadata">

**Author:** ![xwu](https://avatars.discourse-cdn.com/v4/letter/x/b487fb/32.png) [@xwu](https://forums.swift.org/u/xwu)\
**Post date:** [July 17, 2024, 5:43am UTC](https://forums.swift.org/t/throwing-subscript-setters/73224/2 "2024-07-17T05:43:06Z")

</div>

No one has implemented it.

> [@Proposal: Allow Getters and Setters to Throw](https://forums.swift.org/t/proposal-allow-getters-and-setters-to-throw/191/3):
>
> I consider all of these implementation limitations, not intentional parts of the design of Swift. Patches would be very very welcome to help improve these areas.

> [@Proposal: Allow Getters and Setters to Throw](https://forums.swift.org/t/proposal-allow-getters-and-setters-to-throw/191/18):
>
> If someone wants to pick this up, I’d be happy to guide them through the implementation. There’s some fairly serious compiler work involved, though, including adding new kinds of apply instruction to SIL.

It is hard, as discussed in SE-0310:

> The main purpose of imposing this read-only restriction is to limit the scope of this proposal to a simple, useful, and easy-to-understand feature. Limiting effects specifiers to read-only properties and subscripts in this proposal does _not_ prevent future proposals from offering them for mutable members. [For more discussion of why effectful setters are tricky, see the "Extensions considered" section of this proposal.](https://github.com/swiftlang/swift-evolution/blob/main/proposals/0310-effectful-readonly-properties.md#effectful-settable-properties)
