# I know Nothing in Kotlin

DevFeed: [I know Nothing in Kotlin](<https://devfeed.tech/articles/i-know-nothing-in-kotlin-23971.md>)

Original publisher: [Read original article](<https://medium.com/making-meetup/i-know-nothing-in-kotlin-392a85bcc3b4?source=rss----6981e268ba45---4>)

Author: Colin Lee

Published: 2022-09-16T15:32:41Z

Content type: article

Language: en

Sources: [Making Meetup - Medium](<https://devfeed.tech/sources/making-meetup-medium.md>)

Topics: [Kotlin](<https://devfeed.tech/topics/kotlin.md>), [Exception](<https://devfeed.tech/topics/exception.md>), [Exception handling](<https://devfeed.tech/topics/exception-handling.md>), [typesafety](<https://devfeed.tech/topics/typesafety.md>), [Coroutines](<https://devfeed.tech/topics/coroutines.md>), [Swift](<https://devfeed.tech/topics/swift.md>)

Tags: [cancellation](<https://devfeed.tech/tags/cancellation.md>), [code](<https://devfeed.tech/tags/code.md>), [coroutines](<https://devfeed.tech/tags/coroutines.md>), [dns](<https://devfeed.tech/tags/dns.md>), [errors](<https://devfeed.tech/tags/errors.md>), [exception](<https://devfeed.tech/tags/exception.md>), [exception-handling](<https://devfeed.tech/tags/exception-handling.md>), [function](<https://devfeed.tech/tags/function.md>), [ios](<https://devfeed.tech/tags/ios.md>), [kmm](<https://devfeed.tech/tags/kmm.md>), [kotlin](<https://devfeed.tech/tags/kotlin.md>), [kotlin-multiplatform-mobile](<https://devfeed.tech/tags/kotlin-multiplatform-mobile.md>), [nothing](<https://devfeed.tech/tags/nothing.md>), [pairing](<https://devfeed.tech/tags/pairing.md>), [refactor](<https://devfeed.tech/tags/refactor.md>), [repository](<https://devfeed.tech/tags/repository.md>), [swift](<https://devfeed.tech/tags/swift.md>), [timeout](<https://devfeed.tech/tags/timeout.md>), [type](<https://devfeed.tech/tags/type.md>), [types](<https://devfeed.tech/tags/types.md>)

## AI overview

Kotlin's `Nothing` return type marks code that can never produce a value because it always throws or otherwise does not return. In the article's KMM repository example, a shared error handler rethrows coroutine `CancellationException`s and wraps other exceptions for Swift-facing `@Throws` declarations; declaring its return type as `Nothing` lets callers retain their actual return types. The article says this also helps the compiler and IDE flag unreachable code, and describes `LinkedList<Nothing>` for an empty generic sealed-list variant and `() -> Nothing` for Swift-style guard behavior. It argues against automatic inference because checking every branch could slow compiler and IDE checks and infer surprising types that may cause bugs.

## Source excerpt

When the Greek philosopher Socrates professed that "I know only one thing -- that I know nothing," he wasn't exactly professing ignorance. It was an ancient formulation of the Dunning-Kruger effect. He had discovered that the more he learned, the wider the expanse of human knowledge seemed and the less that it seemed he knew. A fool, on the other hand, might believe that they're "not smart, but genius... and a very stable genius at that," and that they know "only the best words." In this sense, it's a good thing to know nothing. It's also true in Kotlin. During a recent code pairing session, I discovered that in Kotlin, there are numerous developers who have written code in the language for many years. And yet, they still don't know Nothing. Our pairing session became a big fuss about Nothing. We were working on some Repository code in our shared Kotlin Multiplatform Mobile (KMM) module of our Meetup for Organizers app. In this code, there was a repeated block at the end of every repository call to handle network, DNS, and timeout errors. We decided it would make sense to refactor this block into a function as we used it so often. The repeated block in question handled a catch block. It had to re-throw any CancellationExceptions to allow cooperative cancellation of coroutines. Then we had to wrap any other exception and re-throw it as a custom exception type so that we can easily tell iOS a complete list of all types we intend to throw in a @Throws declaration. This allows exception handling and avoids crashing when our functions are called by Swift code. In essence, this code block always threw an Exception. The pairing session became quite funny, like the Laurel and Hardy "Who's on First" comedy routine, but you could tell there was Nothing more frustrating, too. It went something like this: "Why am I getting this red text at the call site?" "The return type is incorrect because you always throw an exception. You need to return Nothing." "I already am returning nothi