Why kotlin allows such code? :wink: ```throw throw...
# random
o
Why kotlin allows such code? 😉
Copy code
throw throw RuntimeException("i am double throw")
k
I guess it is related to try/catch being expression and throw "returning"
Nothing
y
throw is of type
Nothing
, which can be used everywhere and anywhere. This example obviously is silly, but a more realistic one is:
Copy code
throw if(conditionToThrowCustomException) prepareAndThrowCustomException() else RuntimeException("something else failed")
Now sure, you can refactor this to not require the
Nothing
"quirk", but it is still pretty useful and it isn't unintuitive per se
i
Something similar with
return
has been discussed here 🙂 https://kotlinlang.slack.com/archives/C09222272/p1645799061136249
o
thanks 😉
c
does idea warn about it?