# \[Pitch\] Optional.orThrow

**URL:** <https://forums.swift.org/t/pitch-optional-orthrow/69995>\
**Category:** Pitches\
**Created:** [February 12, 2024, 9:34pm UTC](https://forums.swift.org/t/pitch-optional-orthrow/69995 "2024-02-12T21:34:35Z")\
**Posts on this page:** 1\
**Showing post:** 20

<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:** [April 9, 2024, 12:55am UTC](https://forums.swift.org/t/pitch-optional-orthrow/69995/20 "2024-04-09T00:55:25Z")

</div>

Worth to note: there's a critical difference between `x!` and anything we've brought up so far: `x!` could be used as an L-value:

```swift
x! = value
x!.mutatingFunc()
x![1] = value
x!.field = value

```

whereas

`try x ?? throw error = value`

or a similar syntax would result in:

// 🛑 Cannot assign to value: binary operator returns immutable value

Would be cool if the "throwing optional unwrap" equivalent supported L-value usage scenario.

* * *

In light of the L-value issue, here's another suggestion: introduce a special built-in postfix `^` "operator", that for all intents and purposes works like `!` except it throws on nil instead of terminating the app:

```swift
try x^.mutatingFunction()
try x^ = value
try x^[1] = value
try x^.field = value
value = try x^

```

When the value is nil it'd throw some fixed non customisable "Nil" error.

That'd require a compiler change as it can't be done by current language means.

Similarly `as^` could be a throwing version of `as!`

---

_[View the full topic](https://forums.swift.org/t/pitch-optional-orthrow/69995)._
