# RFC: Allow throwing an exception as right part of null coalescing operator

- Thread: https://externals.io/message/100024
- Original archive: https://news-web.php.net/php.internals/100024
- Started by Tim Bezhashvyly on 2017-07-24T07:37:07+00:00
- Messages: 2
- Reply by email to internals@lists.php.net
- More for agents: search with https://externals.io/search.md?q={query} · RFCs at https://externals.io/rfc.md · JSON API at https://externals.io/api · documentation at https://externals.io/llms.txt

---

## #100024 — Tim Bezhashvyly — 2017-07-24T07:37:07+00:00

URL: https://externals.io/message/100024#100024

Dear internals,

Don't you think allowing to throw an exception as the right side of null coalescing operator would be a good idea?

Something like:

echo $a ?? throw new \RuntimeException('foo');

Regards,
Tim

---

## #100030 — Niklas Keller — 2017-07-24T09:54:05+00:00

URL: https://externals.io/message/100024#100030 · In reply to: #100024

>
> Dear internals,
>
> Don't you think allowing to throw an exception as the right side of null
> coalescing operator would be a good idea?
>
> Something like:
>
> echo $a ?? throw new \RuntimeException('foo');
>
> Regards,
> Tim
>

Sometimes that would be really helpful. What you can do is something like
that:

function raise(Throwable $t) {
    throw $t;
}

$a = $a ?? raise(new \RuntimeException("foo"));

Regards, Niklas
