Kotlin notNull assurance exceptions? | SoloLearn: Learn to code for FREE!


Kotlin notNull assurance exceptions?

For example, readLine()!! makes an exception if the input is empty. Should I cover it up with try-catch? Or is it a checked exception that I don't have to manage it?

3/23/2018 6:44:38 AM

Hojun Sa

7 Answers

New Answer


Personally, I try to handle all exceptions that can be generated by the user's actions. I have forced readline to return null so I always handle it. Things that I know can't happen like an initialized variable I default to null, but change prior to executing the current function. I don't bother putting code to catch what won't or shouldn't happen.


yes, you should. Checked exception are not pass compiler...


Kotlin does not have checked exceptions. This link provides reasons why. https://kotlinlang.org/docs/reference/exceptions.html


bornToCode() thanks for pointing that out as I missed it.


@Vukan I heared that in kotlin, checked exceptions can be passed. So I'm asking whether managing this is necessary for the user.


Interesting, so actually, try catch blocks are treated as expressions...


does kotlin really has checked exceptions. talk me more on this, do please. while yes, catch them all to be good boy