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

+5

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

+6

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.

+9

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

+7

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

+7

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

+4

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

+3

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

+1

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