<html><head><meta http-equiv="Content-Type" content="text/html charset=utf-8"></head><body style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space;" class="">As a number of recent threads have shown, typed throws and error handling is a complicated topic with a lot of implications.<div class=""><br class=""></div><div class="">However in the mean time we could potentially address one of the pain points people give for wanting typed throws - exhaustive catch statements.</div><div class=""><br class=""></div><div class="">For functions that you completely control, it is possible to be completely certain of the errors the function will throw and it is an unrecoverable logical error for any other error to be thrown. Currently this situation would have to be handled like so-</div><div class=""><br class=""></div><div class=""><div style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo;" class=""><span style="font-variant-ligatures: no-common-ligatures; color: rgb(186, 45, 162);" class="">do</span><span style="font-variant-ligatures: no-common-ligatures;" class="">&nbsp;{</span></div><div style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo; color: rgb(49, 89, 93);" class=""><span style="font-variant-ligatures: no-common-ligatures; color: rgb(0, 0, 0);" class="">&nbsp; &nbsp;&nbsp;</span><span style="font-variant-ligatures: no-common-ligatures; color: rgb(186, 45, 162);" class="">try</span><span style="font-variant-ligatures: no-common-ligatures; color: rgb(0, 0, 0);" class="">&nbsp;</span><span style="font-variant-ligatures: no-common-ligatures;" class="">throwingFunction</span><span style="font-variant-ligatures: no-common-ligatures; color: rgb(0, 0, 0);" class="">()</span></div><div style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo;" class=""><span style="font-variant-ligatures: no-common-ligatures;" class="">}&nbsp;</span><span style="font-variant-ligatures: no-common-ligatures; color: rgb(186, 45, 162);" class="">catch</span><span style="font-variant-ligatures: no-common-ligatures;" class="">&nbsp;MyError.</span><span style="font-variant-ligatures: no-common-ligatures; color: rgb(49, 89, 93);" class="">TheError</span><span style="font-variant-ligatures: no-common-ligatures;" class=""><span style="font-variant-ligatures: no-common-ligatures;" class="">(</span><span style="font-variant-ligatures: no-common-ligatures; color: rgb(186, 45, 162);" class="">let</span><span style="font-variant-ligatures: no-common-ligatures;" class="">&nbsp;theContext)</span>&nbsp;{</span></div><div style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo; color: rgb(0, 132, 0);" class=""><span style="font-variant-ligatures: no-common-ligatures; color: rgb(0, 0, 0);" class="">&nbsp; &nbsp;&nbsp;</span><span style="font-variant-ligatures: no-common-ligatures;" class="">// do something</span></div><div style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo; color: rgb(186, 45, 162);" class=""><span style="font-variant-ligatures: no-common-ligatures; color: rgb(0, 0, 0);" class="">}&nbsp;</span><span style="font-variant-ligatures: no-common-ligatures;" class="">catch</span><span style="font-variant-ligatures: no-common-ligatures; color: rgb(0, 0, 0);" class="">&nbsp;{</span></div><div style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo; color: rgb(209, 47, 27);" class=""><span style="font-variant-ligatures: no-common-ligatures; color: rgb(0, 0, 0);" class="">&nbsp; &nbsp;&nbsp;</span><span style="font-variant-ligatures: no-common-ligatures; color: rgb(62, 30, 129);" class="">fatalError</span><span style="font-variant-ligatures: no-common-ligatures; color: rgb(0, 0, 0);" class="">(</span><span style="font-variant-ligatures: no-common-ligatures;" class="">“Impossible error?"</span><span style="font-variant-ligatures: no-common-ligatures; color: rgb(0, 0, 0);" class="">)</span></div><div style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo;" class=""><span style="font-variant-ligatures: no-common-ligatures;" class="">}</span></div></div><div class=""><br class=""></div><div class="">Here, the catch-all is just boilerplate to make the catch statement exhaustive but doesn’t provide any value to the programmer. Would it make sense to provide a shorthand for this case like this-</div><div class=""><br class=""></div><div class=""><div style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo;" class=""><span style="font-variant-ligatures: no-common-ligatures; color: rgb(186, 45, 162);" class="">do</span><span style="font-variant-ligatures: no-common-ligatures;" class="">&nbsp;{</span></div><div style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo; color: rgb(49, 89, 93);" class=""><span style="font-variant-ligatures: no-common-ligatures; color: rgb(0, 0, 0);" class="">&nbsp; &nbsp;&nbsp;</span><span style="font-variant-ligatures: no-common-ligatures; color: rgb(186, 45, 162);" class="">try</span><span style="font-variant-ligatures: no-common-ligatures; color: rgb(0, 0, 0);" class="">!&nbsp;</span><span style="font-variant-ligatures: no-common-ligatures;" class="">throwingFunction</span><span style="font-variant-ligatures: no-common-ligatures; color: rgb(0, 0, 0);" class="">()</span></div><div style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo;" class=""><span style="font-variant-ligatures: no-common-ligatures;" class="">}&nbsp;</span><span style="font-variant-ligatures: no-common-ligatures; color: rgb(186, 45, 162);" class="">catch</span><span style="font-variant-ligatures: no-common-ligatures;" class="">&nbsp;MyError.</span><span style="font-variant-ligatures: no-common-ligatures; color: rgb(49, 89, 93);" class="">TheError</span><span style="font-variant-ligatures: no-common-ligatures;" class="">(</span><span style="font-variant-ligatures: no-common-ligatures; color: rgb(186, 45, 162);" class="">let</span><span style="font-variant-ligatures: no-common-ligatures;" class="">&nbsp;theContext)&nbsp;</span>{</div><div style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo; color: rgb(0, 132, 0);" class=""><span style="font-variant-ligatures: no-common-ligatures; color: rgb(0, 0, 0);" class="">&nbsp; &nbsp;&nbsp;</span><span style="font-variant-ligatures: no-common-ligatures;" class="">// do something</span></div><div style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo;" class=""><span style="font-variant-ligatures: no-common-ligatures;" class="">}</span></div></div><div class=""><br class=""></div><div class="">Where the&nbsp;<span style="color: rgb(186, 45, 162); font-family: Menlo; font-size: 11px; font-variant-ligatures: no-common-ligatures;" class="">try</span><span style="font-family: Menlo; font-size: 11px; font-variant-ligatures: no-common-ligatures;" class="">!</span>&nbsp;still indicates the call could fatalError if the function throws an unmatched error but allows the programmer to specify the errors that they specifically want to handle. I don’t think this moves the language away from the possibility of typed throws; adding typed throws would likely cause a warning in both cases - either to remove the catch-all or all the ! - if the compiler could determine the catch was now exhaustive without them.</div><div class=""><br class=""></div><div class="">If this has been proposed elsewhere I apologise.&nbsp;</div><div class=""><br class=""></div><div class="">Cheers,</div><div class="">Simon</div></body></html>