https://kotlinlang.org logo
#announcements
Title
# announcements
r

Ruckus

12/03/2019, 5:06 PM
Quick question that just bit me, why does
TODO()
throw an
Error
instead of an
Exception
? The KDoc for
NotImplementedError
says: > An exception is thrown to indicate that a method body remains to be implemented. (It's extra weird considering
error()
throws an
Exception
)
s

streetsofboston

12/03/2019, 5:09 PM
It is an
Error
because it is a structural error in your code, not some exceptional condition from an external context/system.
🤔 1
r

Ruckus

12/03/2019, 5:10 PM
I guess that makes sense. Still feels a little weird for some reason I can't place my finger on.
s

streetsofboston

12/03/2019, 5:15 PM
Broadly stated: • A Throwable is either an Exception or an Error. • An Exception can be a RuntimeException (although, all Throwables are unchecked in Kotlin)
c

Casey Brooks

12/03/2019, 5:19 PM
Errors usually indicate something is seriously wrong with your dev environment or the way you’ve written your code. They are problems that should be fixed before trying to run your code again, as your program cannot work until you do. In this sense, errors are more akin to a compiler error than an exception, only that they’re detected at runtime. Thus, the library creators intended that the solution to a TODO isn’t to catch the exception and handle it. It’s to refactor your code so you’re not calling that method, since it’s clearly not ready for use.
2
☝️ 3
r

Ruckus

12/03/2019, 5:46 PM
Okay, that makes sense. I'm coming around to the idea. I think the KDoc I mentioned is wrong then. Should I file an issue, or do you all think it's okay as is?
s

streetsofboston

12/03/2019, 5:54 PM
What is wrong with the KDoc? If it is the word ‘exception’, it is not really wrong. Exception is a generic term (outside of Java as well) for something that a function can throw in an exceptional situation.
r

Ruckus

12/03/2019, 6:14 PM
But
Exception
is not a generic term in this case. It's a specific class that is not part of the hierarchy of
NotImplementedError
.
s

streetsofboston

12/03/2019, 6:19 PM
Me being nitpicky 🙂: The word was written with a lower-case ‘e’… this indicates it being used as a generic term and not a class-name.
r

Ruckus

12/03/2019, 6:22 PM
I see what you're saying, but that nuance in implied distinction can be confusing for native English speakers, let alone for those who speak it as a second language.
I went ahead and filed an issue. You can comment on it if you wish. On the whole it's decidedly not important, but I figured: why not? https://youtrack.jetbrains.com/issue/KT-35263
🙂 1
4 Views