<div dir="ltr"><div class="gmail_quote"><div dir="ltr">Hello,<div><br></div><div>Consider the scenario of the vending machine example in the Swift Book:</div><div><br></div><div>We have a function that throws errors from a single given ErrorType</div><div><br></div><div><ol style="border:0px;font-size:14px;margin:0px;outline:0px;padding:0px;vertical-align:baseline;line-height:1.6em;list-style:none;color:rgb(0,0,0);font-family:helvetica,arial,sans-serif;background-image:initial;background-repeat:initial"><li style="border-width:0px 0px 0px 18px;border-left-style:solid;border-left-color:transparent;margin:0px;outline:0px;padding:0px 10px 0px 0px;vertical-align:baseline;white-space:pre-wrap;list-style-type:none;background-image:initial;background-color:transparent;background-position:initial;background-repeat:initial"><code style="border:0px;font-size:0.85em;margin:0px;outline:0px;padding:0px;vertical-align:baseline;font-family:menlo,monospace;word-wrap:break-word;background-image:initial;background-color:transparent;background-position:initial;background-repeat:initial"><span style="border:0px;font-size:11.9px;margin:0px;outline:0px;padding:0px;vertical-align:baseline;color:rgb(170,51,145);background-image:initial;background-color:transparent;background-position:initial;background-repeat:initial">func</span> <span style="border:0px;font-size:11.9px;margin:0px;outline:0px;padding:0px;vertical-align:baseline;color:rgb(63,110,116);background-image:initial;background-color:transparent;background-position:initial;background-repeat:initial">vend</span>(<span style="border:0px;font-size:11.9px;margin:0px;outline:0px;padding:0px;vertical-align:baseline;color:rgb(63,110,116);background-image:initial;background-color:transparent;background-position:initial;background-repeat:initial">itemNamed</span> <span style="border:0px;font-size:11.9px;margin:0px;outline:0px;padding:0px;vertical-align:baseline;color:rgb(63,110,116);background-image:initial;background-color:transparent;background-position:initial;background-repeat:initial">name</span>: <span style="border:0px;font-size:11.9px;margin:0px;outline:0px;padding:0px;vertical-align:baseline;color:rgb(92,38,153);background-image:initial;background-color:transparent;background-position:initial;background-repeat:initial">String</span>) <span style="border:0px;font-size:11.9px;margin:0px;outline:0px;padding:0px;vertical-align:baseline;color:rgb(170,51,145);background-image:initial;background-color:transparent;background-position:initial;background-repeat:initial">throws</span> {</code></li><li style="border-width:0px 0px 0px 18px;border-left-style:solid;border-left-color:transparent;margin:0px;outline:0px;padding:0px 10px 0px 0px;vertical-align:baseline;white-space:pre-wrap;list-style-type:none;background-image:initial;background-color:transparent;background-position:initial;background-repeat:initial"><code style="border:0px;font-size:0.85em;margin:0px;outline:0px;padding:0px;vertical-align:baseline;font-family:menlo,monospace;word-wrap:break-word;background-image:initial;background-color:transparent;background-position:initial;background-repeat:initial">        <span style="border:0px;font-size:11.9px;margin:0px;outline:0px;padding:0px;vertical-align:baseline;color:rgb(170,51,145);background-image:initial;background-color:transparent;background-position:initial;background-repeat:initial">guard</span> <span style="border:0px;font-size:11.9px;margin:0px;outline:0px;padding:0px;vertical-align:baseline;color:rgb(170,51,145);background-image:initial;background-color:transparent;background-position:initial;background-repeat:initial">let</span> <span style="border:0px;font-size:11.9px;margin:0px;outline:0px;padding:0px;vertical-align:baseline;color:rgb(63,110,116);background-image:initial;background-color:transparent;background-position:initial;background-repeat:initial">item</span> = <span style="border:0px;font-size:11.9px;margin:0px;outline:0px;padding:0px;vertical-align:baseline;color:rgb(63,110,116);background-image:initial;background-color:transparent;background-position:initial;background-repeat:initial">inventory</span>[<span style="border:0px;font-size:11.9px;margin:0px;outline:0px;padding:0px;vertical-align:baseline;color:rgb(63,110,116);background-image:initial;background-color:transparent;background-position:initial;background-repeat:initial">name</span>] <span style="border:0px;font-size:11.9px;margin:0px;outline:0px;padding:0px;vertical-align:baseline;color:rgb(170,51,145);background-image:initial;background-color:transparent;background-position:initial;background-repeat:initial">else</span> {</code></li><li style="border-width:0px 0px 0px 18px;border-left-style:solid;border-left-color:transparent;margin:0px;outline:0px;padding:0px 10px 0px 0px;vertical-align:baseline;white-space:pre-wrap;list-style-type:none;background-image:initial;background-color:transparent;background-position:initial;background-repeat:initial"><code style="border:0px;font-size:0.85em;margin:0px;outline:0px;padding:0px;vertical-align:baseline;font-family:menlo,monospace;word-wrap:break-word;background-image:initial;background-color:transparent;background-position:initial;background-repeat:initial">            <span style="border:0px;font-size:11.9px;margin:0px;outline:0px;padding:0px;vertical-align:baseline;color:rgb(170,51,145);background-image:initial;background-color:transparent;background-position:initial;background-repeat:initial">throw</span> <span style="border:0px;font-size:11.9px;margin:0px;outline:0px;padding:0px;vertical-align:baseline;color:rgb(63,110,116);background-image:initial;background-color:transparent;background-position:initial;background-repeat:initial">VendingMachineError</span>.<span style="border:0px;font-size:11.9px;margin:0px;outline:0px;padding:0px;vertical-align:baseline;color:rgb(63,110,116);background-image:initial;background-color:transparent;background-position:initial;background-repeat:initial">InvalidSel<wbr>ection</span></code></li><li style="border-width:0px 0px 0px 18px;border-left-style:solid;border-left-color:transparent;margin:0px;outline:0px;padding:0px 10px 0px 0px;vertical-align:baseline;white-space:pre-wrap;list-style-type:none;background-image:initial;background-color:transparent;background-position:initial;background-repeat:initial"><code style="border:0px;font-size:0.85em;margin:0px;outline:0px;padding:0px;vertical-align:baseline;font-family:menlo,monospace;word-wrap:break-word;background-image:initial;background-color:transparent;background-position:initial;background-repeat:initial">        }</code></li><li style="border-width:0px 0px 0px 18px;border-left-style:solid;border-left-color:transparent;margin:0px;outline:0px;padding:0px 10px 0px 0px;vertical-align:baseline;white-space:pre-wrap;list-style-type:none;background-image:initial;background-color:transparent;background-position:initial;background-repeat:initial"><code style="border:0px;font-size:0.85em;margin:0px;outline:0px;padding:0px;vertical-align:baseline;font-family:menlo,monospace;word-wrap:break-word;background-image:initial;background-color:transparent;background-position:initial;background-repeat:initial">        </code></li><li style="border-width:0px 0px 0px 18px;border-left-style:solid;border-left-color:transparent;margin:0px;outline:0px;padding:0px 10px 0px 0px;vertical-align:baseline;white-space:pre-wrap;list-style-type:none;background-image:initial;background-color:transparent;background-position:initial;background-repeat:initial"><code style="border:0px;font-size:0.85em;margin:0px;outline:0px;padding:0px;vertical-align:baseline;font-family:menlo,monospace;word-wrap:break-word;background-image:initial;background-color:transparent;background-position:initial;background-repeat:initial">        <span style="border:0px;font-size:11.9px;margin:0px;outline:0px;padding:0px;vertical-align:baseline;color:rgb(170,51,145);background-image:initial;background-color:transparent;background-position:initial;background-repeat:initial">guard</span> <span style="border:0px;font-size:11.9px;margin:0px;outline:0px;padding:0px;vertical-align:baseline;color:rgb(63,110,116);background-image:initial;background-color:transparent;background-position:initial;background-repeat:initial">item</span>.<span style="border:0px;font-size:11.9px;margin:0px;outline:0px;padding:0px;vertical-align:baseline;color:rgb(63,110,116);background-image:initial;background-color:transparent;background-position:initial;background-repeat:initial">count</span> &gt; <span style="border:0px;font-size:11.9px;margin:0px;outline:0px;padding:0px;vertical-align:baseline;color:rgb(28,0,207);background-image:initial;background-color:transparent;background-position:initial;background-repeat:initial">0</span> <span style="border:0px;font-size:11.9px;margin:0px;outline:0px;padding:0px;vertical-align:baseline;color:rgb(170,51,145);background-image:initial;background-color:transparent;background-position:initial;background-repeat:initial">else</span> {</code></li><li style="border-width:0px 0px 0px 18px;border-left-style:solid;border-left-color:transparent;margin:0px;outline:0px;padding:0px 10px 0px 0px;vertical-align:baseline;white-space:pre-wrap;list-style-type:none;background-image:initial;background-color:transparent;background-position:initial;background-repeat:initial"><code style="border:0px;font-size:0.85em;margin:0px;outline:0px;padding:0px;vertical-align:baseline;font-family:menlo,monospace;word-wrap:break-word;background-image:initial;background-color:transparent;background-position:initial;background-repeat:initial">            <span style="border:0px;font-size:11.9px;margin:0px;outline:0px;padding:0px;vertical-align:baseline;color:rgb(170,51,145);background-image:initial;background-color:transparent;background-position:initial;background-repeat:initial">throw</span> <span style="border:0px;font-size:11.9px;margin:0px;outline:0px;padding:0px;vertical-align:baseline;color:rgb(63,110,116);background-image:initial;background-color:transparent;background-position:initial;background-repeat:initial">VendingMachineError</span>.<span style="border:0px;font-size:11.9px;margin:0px;outline:0px;padding:0px;vertical-align:baseline;color:rgb(63,110,116);background-image:initial;background-color:transparent;background-position:initial;background-repeat:initial">OutOfStock</span></code></li><li style="border-width:0px 0px 0px 18px;border-left-style:solid;border-left-color:transparent;margin:0px;outline:0px;padding:0px 10px 0px 0px;vertical-align:baseline;white-space:pre-wrap;list-style-type:none;background-image:initial;background-color:transparent;background-position:initial;background-repeat:initial"><code style="border:0px;font-size:0.85em;margin:0px;outline:0px;padding:0px;vertical-align:baseline;font-family:menlo,monospace;word-wrap:break-word;background-image:initial;background-color:transparent;background-position:initial;background-repeat:initial">        }</code></li><li style="border-width:0px 0px 0px 18px;border-left-style:solid;border-left-color:transparent;margin:0px;outline:0px;padding:0px 10px 0px 0px;vertical-align:baseline;white-space:pre-wrap;list-style-type:none;background-image:initial;background-color:transparent;background-position:initial;background-repeat:initial"><code style="border:0px;font-size:0.85em;margin:0px;outline:0px;padding:0px;vertical-align:baseline;font-family:menlo,monospace;word-wrap:break-word;background-image:initial;background-color:transparent;background-position:initial;background-repeat:initial">        </code></li><li style="border-width:0px 0px 0px 18px;border-left-style:solid;border-left-color:transparent;margin:0px;outline:0px;padding:0px 10px 0px 0px;vertical-align:baseline;white-space:pre-wrap;list-style-type:none;background-image:initial;background-color:transparent;background-position:initial;background-repeat:initial"><code style="border:0px;font-size:0.85em;margin:0px;outline:0px;padding:0px;vertical-align:baseline;font-family:menlo,monospace;word-wrap:break-word;background-image:initial;background-color:transparent;background-position:initial;background-repeat:initial">        <span style="border:0px;font-size:11.9px;margin:0px;outline:0px;padding:0px;vertical-align:baseline;color:rgb(170,51,145);background-image:initial;background-color:transparent;background-position:initial;background-repeat:initial">guard</span> <span style="border:0px;font-size:11.9px;margin:0px;outline:0px;padding:0px;vertical-align:baseline;color:rgb(63,110,116);background-image:initial;background-color:transparent;background-position:initial;background-repeat:initial">item</span>.<span style="border:0px;font-size:11.9px;margin:0px;outline:0px;padding:0px;vertical-align:baseline;color:rgb(63,110,116);background-image:initial;background-color:transparent;background-position:initial;background-repeat:initial">price</span> &lt;= <span style="border:0px;font-size:11.9px;margin:0px;outline:0px;padding:0px;vertical-align:baseline;color:rgb(63,110,116);background-image:initial;background-color:transparent;background-position:initial;background-repeat:initial">coinsDeposited</span> <span style="border:0px;font-size:11.9px;margin:0px;outline:0px;padding:0px;vertical-align:baseline;color:rgb(170,51,145);background-image:initial;background-color:transparent;background-position:initial;background-repeat:initial">else</span> {</code></li><li style="border-width:0px 0px 0px 18px;border-left-style:solid;border-left-color:transparent;margin:0px;outline:0px;padding:0px 10px 0px 0px;vertical-align:baseline;white-space:pre-wrap;list-style-type:none;background-image:initial;background-color:transparent;background-position:initial;background-repeat:initial"><code style="border:0px;font-size:0.85em;margin:0px;outline:0px;padding:0px;vertical-align:baseline;font-family:menlo,monospace;word-wrap:break-word;background-image:initial;background-color:transparent;background-position:initial;background-repeat:initial">            <span style="border:0px;font-size:11.9px;margin:0px;outline:0px;padding:0px;vertical-align:baseline;color:rgb(170,51,145);background-image:initial;background-color:transparent;background-position:initial;background-repeat:initial">throw</span> <span style="border:0px;font-size:11.9px;margin:0px;outline:0px;padding:0px;vertical-align:baseline;color:rgb(63,110,116);background-image:initial;background-color:transparent;background-position:initial;background-repeat:initial">VendingMachineError</span>.<span style="border:0px;font-size:11.9px;margin:0px;outline:0px;padding:0px;vertical-align:baseline;color:rgb(63,110,116);background-image:initial;background-color:transparent;background-position:initial;background-repeat:initial">Insufficie<wbr>ntFunds</span>(<span style="border:0px;font-size:11.9px;margin:0px;outline:0px;padding:0px;vertical-align:baseline;color:rgb(63,110,116);background-image:initial;background-color:transparent;background-position:initial;background-repeat:initial">coinsNeeded</span>: <span style="border:0px;font-size:11.9px;margin:0px;outline:0px;padding:0px;vertical-align:baseline;color:rgb(63,110,116);background-image:initial;background-color:transparent;background-position:initial;background-repeat:initial">item</span>.<span style="border:0px;font-size:11.9px;margin:0px;outline:0px;padding:0px;vertical-align:baseline;color:rgb(63,110,116);background-image:initial;background-color:transparent;background-position:initial;background-repeat:initial">price</span> - <span style="border:0px;font-size:11.9px;margin:0px;outline:0px;padding:0px;vertical-align:baseline;color:rgb(63,110,116);background-image:initial;background-color:transparent;background-position:initial;background-repeat:initial">coinsDeposited</span>)</code></li><li style="border-width:0px 0px 0px 18px;border-left-style:solid;border-left-color:transparent;margin:0px;outline:0px;padding:0px 10px 0px 0px;vertical-align:baseline;white-space:pre-wrap;list-style-type:none;background-image:initial;background-color:transparent;background-position:initial;background-repeat:initial"><code style="border:0px;font-size:0.85em;margin:0px;outline:0px;padding:0px;vertical-align:baseline;font-family:menlo,monospace;word-wrap:break-word;background-image:initial;background-color:transparent;background-position:initial;background-repeat:initial">        }</code></li></ol><div><font color="#000000" face="Menlo, monospace"><span style="font-size:11.9px;line-height:22.4px;white-space:pre-wrap"><br></span></font></div></div><div><font color="#000000" face="arial, helvetica, sans-serif"><span style="line-height:22.4px;white-space:pre-wrap">In this scenario - when we have a function that throws a single type of error - I believe it would be useful to be able to <b>optionally</b> specify the type of error thrown from the vend function, so that the code would look like this:</span></font></div><div><font color="#000000" face="arial, helvetica, sans-serif"><span style="line-height:22.4px;white-space:pre-wrap"><br></span></font></div><div><ol style="border:0px;font-size:14px;margin:0px;outline:0px;padding:0px;vertical-align:baseline;line-height:1.6em;list-style:none;font-family:helvetica,arial,sans-serif;background-image:initial;background-repeat:initial"><li style="color:rgb(0,0,0);border-width:0px 0px 0px 18px;border-left-style:solid;border-left-color:transparent;margin:0px;outline:0px;padding:0px 10px 0px 0px;vertical-align:baseline;white-space:pre-wrap;list-style-type:none;background-image:initial;background-color:transparent;background-repeat:initial"><code style="border:0px;font-size:0.85em;margin:0px;outline:0px;padding:0px;vertical-align:baseline;font-family:menlo,monospace;word-wrap:break-word;background-image:initial;background-color:transparent;background-position:initial;background-repeat:initial"><span style="border:0px;font-size:11.9px;margin:0px;outline:0px;padding:0px;vertical-align:baseline;color:rgb(170,51,145);background-image:initial;background-color:transparent;background-position:initial;background-repeat:initial">func</span> <span style="border:0px;font-size:11.9px;margin:0px;outline:0px;padding:0px;vertical-align:baseline;color:rgb(63,110,116);background-image:initial;background-color:transparent;background-position:initial;background-repeat:initial">vend</span>(<span style="border:0px;font-size:11.9px;margin:0px;outline:0px;padding:0px;vertical-align:baseline;color:rgb(63,110,116);background-image:initial;background-color:transparent;background-position:initial;background-repeat:initial">itemNamed</span> <span style="border:0px;font-size:11.9px;margin:0px;outline:0px;padding:0px;vertical-align:baseline;color:rgb(63,110,116);background-image:initial;background-color:transparent;background-position:initial;background-repeat:initial">name</span>: <span style="border:0px;font-size:11.9px;margin:0px;outline:0px;padding:0px;vertical-align:baseline;color:rgb(92,38,153);background-image:initial;background-color:transparent;background-position:initial;background-repeat:initial">String</span>) <span style="border:0px;font-size:11.9px;margin:0px;outline:0px;padding:0px;vertical-align:baseline;color:rgb(170,51,145);background-image:initial;background-color:transparent;background-position:initial;background-repeat:initial">throws</span> <span style="color:rgb(63,110,116);font-size:11.9px;line-height:22.4px">VendingMachineError </span>{</code></li><li style="color:rgb(0,0,0);border-width:0px 0px 0px 18px;border-left-style:solid;border-left-color:transparent;margin:0px;outline:0px;padding:0px 10px 0px 0px;vertical-align:baseline;white-space:pre-wrap;list-style-type:none;background-image:initial;background-color:transparent;background-repeat:initial"><code style="border:0px;font-size:0.85em;margin:0px;outline:0px;padding:0px;vertical-align:baseline;font-family:menlo,monospace;word-wrap:break-word;background-image:initial;background-color:transparent;background-position:initial;background-repeat:initial">        <span style="border:0px;font-size:11.9px;margin:0px;outline:0px;padding:0px;vertical-align:baseline;color:rgb(170,51,145);background-image:initial;background-color:transparent;background-position:initial;background-repeat:initial">guard</span> <span style="border:0px;font-size:11.9px;margin:0px;outline:0px;padding:0px;vertical-align:baseline;color:rgb(170,51,145);background-image:initial;background-color:transparent;background-position:initial;background-repeat:initial">let</span> <span style="border:0px;font-size:11.9px;margin:0px;outline:0px;padding:0px;vertical-align:baseline;color:rgb(63,110,116);background-image:initial;background-color:transparent;background-position:initial;background-repeat:initial">item</span> = <span style="border:0px;font-size:11.9px;margin:0px;outline:0px;padding:0px;vertical-align:baseline;color:rgb(63,110,116);background-image:initial;background-color:transparent;background-position:initial;background-repeat:initial">inventory</span>[<span style="border:0px;font-size:11.9px;margin:0px;outline:0px;padding:0px;vertical-align:baseline;color:rgb(63,110,116);background-image:initial;background-color:transparent;background-position:initial;background-repeat:initial">name</span>] <span style="border:0px;font-size:11.9px;margin:0px;outline:0px;padding:0px;vertical-align:baseline;color:rgb(170,51,145);background-image:initial;background-color:transparent;background-position:initial;background-repeat:initial">else</span> {</code></li><li style="border-width:0px 0px 0px 18px;border-left-style:solid;border-left-color:transparent;margin:0px;outline:0px;padding:0px 10px 0px 0px;vertical-align:baseline;white-space:pre-wrap;list-style-type:none;background-image:initial;background-color:transparent;background-repeat:initial"><code style="border:0px;font-size:0.85em;margin:0px;outline:0px;padding:0px;vertical-align:baseline;font-family:menlo,monospace;word-wrap:break-word;background-image:initial;background-color:transparent;background-repeat:initial"><font color="#000000">            </font><span style="color:rgb(170,51,145);border:0px;font-size:11.9px;margin:0px;outline:0px;padding:0px;vertical-align:baseline;background-image:initial;background-color:transparent;background-repeat:initial">throw</span><span style="border:0px;font-size:11.9px;margin:0px;outline:0px;padding:0px;vertical-align:baseline;background-image:initial;background-color:transparent;background-repeat:initial"><font color="#3f6e74"> </font></span><font color="#000000">.</font><span style="color:rgb(63,110,116);border:0px;font-size:11.9px;margin:0px;outline:0px;padding:0px;vertical-align:baseline;background-image:initial;background-color:transparent;background-repeat:initial">InvalidSelection</span></code></li><li style="color:rgb(0,0,0);border-width:0px 0px 0px 18px;border-left-style:solid;border-left-color:transparent;margin:0px;outline:0px;padding:0px 10px 0px 0px;vertical-align:baseline;white-space:pre-wrap;list-style-type:none;background-image:initial;background-color:transparent;background-repeat:initial"><code style="border:0px;font-size:0.85em;margin:0px;outline:0px;padding:0px;vertical-align:baseline;font-family:menlo,monospace;word-wrap:break-word;background-image:initial;background-color:transparent;background-position:initial;background-repeat:initial">        }</code></li><li style="color:rgb(0,0,0);border-width:0px 0px 0px 18px;border-left-style:solid;border-left-color:transparent;margin:0px;outline:0px;padding:0px 10px 0px 0px;vertical-align:baseline;white-space:pre-wrap;list-style-type:none;background-image:initial;background-color:transparent;background-repeat:initial"><code style="border:0px;font-size:0.85em;margin:0px;outline:0px;padding:0px;vertical-align:baseline;font-family:menlo,monospace;word-wrap:break-word;background-image:initial;background-color:transparent;background-position:initial;background-repeat:initial">        </code></li><li style="color:rgb(0,0,0);border-width:0px 0px 0px 18px;border-left-style:solid;border-left-color:transparent;margin:0px;outline:0px;padding:0px 10px 0px 0px;vertical-align:baseline;white-space:pre-wrap;list-style-type:none;background-image:initial;background-color:transparent;background-repeat:initial"><code style="border:0px;font-size:0.85em;margin:0px;outline:0px;padding:0px;vertical-align:baseline;font-family:menlo,monospace;word-wrap:break-word;background-image:initial;background-color:transparent;background-position:initial;background-repeat:initial">        <span style="border:0px;font-size:11.9px;margin:0px;outline:0px;padding:0px;vertical-align:baseline;color:rgb(170,51,145);background-image:initial;background-color:transparent;background-position:initial;background-repeat:initial">guard</span> <span style="border:0px;font-size:11.9px;margin:0px;outline:0px;padding:0px;vertical-align:baseline;color:rgb(63,110,116);background-image:initial;background-color:transparent;background-position:initial;background-repeat:initial">item</span>.<span style="border:0px;font-size:11.9px;margin:0px;outline:0px;padding:0px;vertical-align:baseline;color:rgb(63,110,116);background-image:initial;background-color:transparent;background-position:initial;background-repeat:initial">count</span> &gt; <span style="border:0px;font-size:11.9px;margin:0px;outline:0px;padding:0px;vertical-align:baseline;color:rgb(28,0,207);background-image:initial;background-color:transparent;background-position:initial;background-repeat:initial">0</span> <span style="border:0px;font-size:11.9px;margin:0px;outline:0px;padding:0px;vertical-align:baseline;color:rgb(170,51,145);background-image:initial;background-color:transparent;background-position:initial;background-repeat:initial">else</span> {</code></li><li style="border-width:0px 0px 0px 18px;border-left-style:solid;border-left-color:transparent;margin:0px;outline:0px;padding:0px 10px 0px 0px;vertical-align:baseline;white-space:pre-wrap;list-style-type:none;background-image:initial;background-color:transparent;background-repeat:initial"><code style="border:0px;font-size:0.85em;margin:0px;outline:0px;padding:0px;vertical-align:baseline;font-family:menlo,monospace;word-wrap:break-word;background-image:initial;background-color:transparent;background-repeat:initial"><font color="#000000">            </font><span style="color:rgb(170,51,145);border:0px;font-size:11.9px;margin:0px;outline:0px;padding:0px;vertical-align:baseline;background-image:initial;background-color:transparent;background-repeat:initial">throw</span><span style="border:0px;font-size:11.9px;margin:0px;outline:0px;padding:0px;vertical-align:baseline;background-image:initial;background-color:transparent;background-repeat:initial"><font color="#3f6e74"> </font></span><font color="#000000">.</font><span style="color:rgb(63,110,116);border:0px;font-size:11.9px;margin:0px;outline:0px;padding:0px;vertical-align:baseline;background-image:initial;background-color:transparent;background-repeat:initial">OutOfStock</span></code></li><li style="color:rgb(0,0,0);border-width:0px 0px 0px 18px;border-left-style:solid;border-left-color:transparent;margin:0px;outline:0px;padding:0px 10px 0px 0px;vertical-align:baseline;white-space:pre-wrap;list-style-type:none;background-image:initial;background-color:transparent;background-repeat:initial"><code style="border:0px;font-size:0.85em;margin:0px;outline:0px;padding:0px;vertical-align:baseline;font-family:menlo,monospace;word-wrap:break-word;background-image:initial;background-color:transparent;background-position:initial;background-repeat:initial">        }</code></li><li style="color:rgb(0,0,0);border-width:0px 0px 0px 18px;border-left-style:solid;border-left-color:transparent;margin:0px;outline:0px;padding:0px 10px 0px 0px;vertical-align:baseline;white-space:pre-wrap;list-style-type:none;background-image:initial;background-color:transparent;background-repeat:initial"><code style="border:0px;font-size:0.85em;margin:0px;outline:0px;padding:0px;vertical-align:baseline;font-family:menlo,monospace;word-wrap:break-word;background-image:initial;background-color:transparent;background-position:initial;background-repeat:initial">        </code></li><li style="color:rgb(0,0,0);border-width:0px 0px 0px 18px;border-left-style:solid;border-left-color:transparent;margin:0px;outline:0px;padding:0px 10px 0px 0px;vertical-align:baseline;white-space:pre-wrap;list-style-type:none;background-image:initial;background-color:transparent;background-repeat:initial"><code style="border:0px;font-size:0.85em;margin:0px;outline:0px;padding:0px;vertical-align:baseline;font-family:menlo,monospace;word-wrap:break-word;background-image:initial;background-color:transparent;background-position:initial;background-repeat:initial">        <span style="border:0px;font-size:11.9px;margin:0px;outline:0px;padding:0px;vertical-align:baseline;color:rgb(170,51,145);background-image:initial;background-color:transparent;background-position:initial;background-repeat:initial">guard</span> <span style="border:0px;font-size:11.9px;margin:0px;outline:0px;padding:0px;vertical-align:baseline;color:rgb(63,110,116);background-image:initial;background-color:transparent;background-position:initial;background-repeat:initial">item</span>.<span style="border:0px;font-size:11.9px;margin:0px;outline:0px;padding:0px;vertical-align:baseline;color:rgb(63,110,116);background-image:initial;background-color:transparent;background-position:initial;background-repeat:initial">price</span> &lt;= <span style="border:0px;font-size:11.9px;margin:0px;outline:0px;padding:0px;vertical-align:baseline;color:rgb(63,110,116);background-image:initial;background-color:transparent;background-position:initial;background-repeat:initial">coinsDeposited</span> <span style="border:0px;font-size:11.9px;margin:0px;outline:0px;padding:0px;vertical-align:baseline;color:rgb(170,51,145);background-image:initial;background-color:transparent;background-position:initial;background-repeat:initial">else</span> {</code></li><li style="border-width:0px 0px 0px 18px;border-left-style:solid;border-left-color:transparent;margin:0px;outline:0px;padding:0px 10px 0px 0px;vertical-align:baseline;white-space:pre-wrap;list-style-type:none;background-image:initial;background-color:transparent;background-repeat:initial"><code style="border:0px;font-size:0.85em;margin:0px;outline:0px;padding:0px;vertical-align:baseline;font-family:menlo,monospace;word-wrap:break-word;background-image:initial;background-color:transparent;background-repeat:initial"><font color="#000000">            </font><span style="color:rgb(170,51,145);border:0px;font-size:11.9px;margin:0px;outline:0px;padding:0px;vertical-align:baseline;background-image:initial;background-color:transparent;background-repeat:initial">throw</span><span style="border:0px;font-size:11.9px;margin:0px;outline:0px;padding:0px;vertical-align:baseline;background-image:initial;background-color:transparent;background-repeat:initial"><font color="#3f6e74"> </font></span><font color="#000000">.</font><span style="color:rgb(63,110,116);border:0px;font-size:11.9px;margin:0px;outline:0px;padding:0px;vertical-align:baseline;background-image:initial;background-color:transparent;background-repeat:initial">InsufficientFunds</span><font color="#000000">(</font><span style="color:rgb(63,110,116);border:0px;font-size:11.9px;margin:0px;outline:0px;padding:0px;vertical-align:baseline;background-image:initial;background-color:transparent;background-repeat:initial">coinsNeeded</span><font color="#000000"><wbr>: </font><span style="color:rgb(63,110,116);border:0px;font-size:11.9px;margin:0px;outline:0px;padding:0px;vertical-align:baseline;background-image:initial;background-color:transparent;background-repeat:initial">item</span><font color="#000000">.</font><span style="color:rgb(63,110,116);border:0px;font-size:11.9px;margin:0px;outline:0px;padding:0px;vertical-align:baseline;background-image:initial;background-color:transparent;background-repeat:initial">price</span><font color="#000000"> - </font><span style="color:rgb(63,110,116);border:0px;font-size:11.9px;margin:0px;outline:0px;padding:0px;vertical-align:baseline;background-image:initial;background-color:transparent;background-repeat:initial">coinsDeposited</span><font color="#000000">)</font></code></li><li style="color:rgb(0,0,0);border-width:0px 0px 0px 18px;border-left-style:solid;border-left-color:transparent;margin:0px;outline:0px;padding:0px 10px 0px 0px;vertical-align:baseline;white-space:pre-wrap;list-style-type:none;background-image:initial;background-color:transparent;background-repeat:initial"><code style="border:0px;font-size:0.85em;margin:0px;outline:0px;padding:0px;vertical-align:baseline;font-family:menlo,monospace;word-wrap:break-word;background-image:initial;background-color:transparent;background-position:initial;background-repeat:initial">        }</code></li></ol></div><div><font color="#000000" face="arial, helvetica, sans-serif"><span style="line-height:22.4px;white-space:pre-wrap"><br></span></font></div><div><font color="#000000" face="arial, helvetica, sans-serif"><span style="line-height:22.4px;white-space:pre-wrap">The purpose is to just let the compiler know that all errors thrown from this function will be of type </span></font><span style="color:rgb(63,110,116);font-family:menlo,monospace;font-size:11.9px;line-height:22.4px;white-space:pre-wrap">VendingMachineError </span><font color="#000000" face="arial, helvetica, sans-serif"><span style="line-height:22.4px;white-space:pre-wrap">so there&#39;s no longer any need to constantly prefix the enumeration cases with the enumeration type.</span></font></div><div><font color="#000000" face="arial, helvetica, sans-serif"><span style="line-height:22.4px;white-space:pre-wrap"><br></span></font></div><div><font color="#000000" face="arial, helvetica, sans-serif"><span style="line-height:22.4px;white-space:pre-wrap">This makes the code much cleaner to read and stops repetition of </span></font><span style="color:rgb(63,110,116);font-family:menlo,monospace;font-size:11.9px;line-height:22.4px;white-space:pre-wrap">VendingMachineError. </span><span style="font-size:11.9px;line-height:22.4px;white-space:pre-wrap"><font color="#000000" face="arial, helvetica, sans-serif">In the scenario where there&#39;s multiple types of errors thrown from a function, using </font></span><span style="color:rgb(170,51,145);font-family:menlo,monospace;font-size:11.9px;line-height:22.4px;white-space:pre-wrap">throws </span><span style="color:rgb(0,0,0);font-family:arial,helvetica,sans-serif;font-size:11.9px;line-height:22.4px;white-space:pre-wrap">as we do now without a type </span><span style="color:rgb(0,0,0);font-family:arial,helvetica,sans-serif;font-size:11.9px;line-height:22.4px;white-space:pre-wrap">would suffice, as in this case it makes sense that the programmer has to tell the compiler what type the Error is via prefixing the </span><span style="color:rgb(0,0,0);font-family:arial,helvetica,sans-serif;line-height:22.4px;white-space:pre-wrap">enumeration case with the </span><span style="color:rgb(0,0,0);font-family:arial,helvetica,sans-serif;line-height:22.4px;white-space:pre-wrap">enumeration type.</span></div><div><br></div><div><span style="color:rgb(0,0,0);font-family:arial,helvetica,sans-serif;line-height:22.4px;white-space:pre-wrap">Cheers,</span></div><div><span style="color:rgb(0,0,0);font-family:arial,helvetica,sans-serif;line-height:22.4px;white-space:pre-wrap">Mark</span></div></div>
</div><br></div>