# 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: tutorial

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>), [multiplatform](<https://devfeed.tech/topics/multiplatform.md>), [Coroutines](<https://devfeed.tech/topics/coroutines.md>), [iOS](<https://devfeed.tech/topics/ios.md>), [Swift](<https://devfeed.tech/topics/swift.md>)

Tags: [coroutines](<https://devfeed.tech/tags/coroutines.md>), [dns](<https://devfeed.tech/tags/dns.md>), [exception](<https://devfeed.tech/tags/exception.md>), [exception-handling](<https://devfeed.tech/tags/exception-handling.md>), [ios](<https://devfeed.tech/tags/ios.md>), [kotlin](<https://devfeed.tech/tags/kotlin.md>), [kotlin-multiplatform-mobile](<https://devfeed.tech/tags/kotlin-multiplatform-mobile.md>), [network](<https://devfeed.tech/tags/network.md>), [nothing](<https://devfeed.tech/tags/nothing.md>), [refactor](<https://devfeed.tech/tags/refactor.md>), [swift](<https://devfeed.tech/tags/swift.md>), [timeout](<https://devfeed.tech/tags/timeout.md>)

## AI overview

This article explains Kotlin's Nothing type through a code-pairing example involving repository calls in a shared Kotlin Multiplatform Mobile module. It describes refactoring repeated exception handling, rethrowing CancellationExceptions for cooperative coroutine cancellation, and using Nothing for functions that always throw.

## 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