# non-nullish throw syntax: \`throw?\`

**URL:** <https://es.discourse.group/t/non-nullish-throw-syntax-throw/2232>\
**Category:** 💡 Ideas\
**Tags:** proposal\
**Created:** [December 2, 2024, 6:10am UTC](https://es.discourse.group/t/non-nullish-throw-syntax-throw/2232 "2024-12-02T06:10:18Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![trusktr](https://yyz2.discourse-cdn.com/free1/user_avatar/es.discourse.group/trusktr/32/183_2.png) [@trusktr](https://es.discourse.group/u/trusktr)\
**Post date:** [December 2, 2024, 6:10am UTC](https://es.discourse.group/t/non-nullish-throw-syntax-throw/2232/1 "2024-12-02T06:10:18Z")

</div>

`throw? maybeError` would be more convenient than `if (maybeError) throw maybeError`.

Sometimes, if you have an error returning function, you want to throw it (if you decide not to use other logic for the return value):

```js
if (validate(foo)) throw validate(foo)

```

where `validate` returns an error if invalid, otherwise null. This is duplicating the amount of work though, and not as DRY.

So next you:

```js
const err = validate(foo)
if (err) throw err

```

But with nullish throw you could shorten this to:

```js
const err = validate(foo)
throw? err

```

or just

```js
throw? validate(foo)

```
