Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Throw expressions #51

Closed
thekid opened this issue Jun 17, 2018 · 4 comments
Closed

Throw expressions #51

thekid opened this issue Jun 17, 2018 · 4 comments

Comments

@thekid
Copy link
Member

thekid commented Jun 17, 2018

In a nutshell

return $user ?? throw new IllegalStateException('No such user');

Would be allowed for the ternary operator, the null-coalesing operator and inside of compact functions.

See also

@thekid
Copy link
Member Author

thekid commented Jun 17, 2018

Could be realized by an IIFE:

// Given this input...
$a ?? throw new \lang\IllegalArgumentException("X");

// ...the compiler would emit this:
$a ?? (function() { throw new \lang\IllegalArgumentException("X"); })()

@thekid
Copy link
Member Author

thekid commented Jun 20, 2018

Good blog article on throws expressions in C# 7.0

http://gunnarpeipman.com/csharp/throw-expressions/

@thekid
Copy link
Member Author

thekid commented Jun 20, 2018

Stackoverflow question covering the problem:

https://stackoverflow.com/questions/9544976/using-throw-in-a-javascript-expression

@thekid
Copy link
Member Author

thekid commented Jun 20, 2018

In Kotlin, throw is an expression:

https://kotlinlang.org/docs/reference/exceptions.html#the-nothing-type

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant