Short Circuits, Bottom Types, and the Vacuous Boomerang

<p>It&rsquo;s a real program, I promise. It compiles and runs.&nbsp;<a href="https://pl.kotl.in/unRa64z1g" rel="noopener ugc nofollow" target="_blank">Try it!</a></p> <p>It works because&nbsp;<code>throw return</code>&nbsp;is an expression of type&nbsp;<code><a href="https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-nothing.html" rel="noopener ugc nofollow" target="_blank">Nothing</a></code>. Normally, an expression is a piece of code that produces a value. When you write something like&nbsp;<code>val x = 1 + 1</code>, you&rsquo;re saying &ldquo;evaluate the expression on the right, and then assign the result to the variable on the left.&rdquo; But when an expression&rsquo;s return type is&nbsp;<code>Nothing</code>, it means the expression never completes its execution at all. Instead, the program exits that line of code entirely, and skips ahead to somewhere else in the program.</p> <p>The&nbsp;<code>throw</code>&nbsp;keyword is a good example of an instruction that can cause a program to skip ahead. When you throw an exception, the program will jump right to the next applicable&nbsp;<code>catch</code>&nbsp;or&nbsp;<code>finally</code>&nbsp;section. Or, if the error isn&rsquo;t caught, the program or thread will crash. Either way, the lines of code after the&nbsp;<code>throw</code>&nbsp;won&rsquo;t get executed.</p> <p><a href="https://betterprogramming.pub/short-circuits-bottom-types-and-the-vacuous-boomerang-2114bca82b3f"><strong>Click Here</strong></a></p> <p>&nbsp;</p>