<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<meta http-equiv="Content-Style-Type" content="text/css">
<title></title>
<meta name="Generator" content="Cocoa HTML Writer">
<meta name="CocoaVersion" content="1404.47">
<style type="text/css">
p.p1 {margin: 0.0px 0.0px 0.0px 0.0px; line-height: 15.0px; font: 12.0px Helvetica; color: #000000}
p.p2 {margin: 0.0px 0.0px 0.0px 0.0px; line-height: 15.0px; font: 12.0px Helvetica; color: #000000; min-height: 14.0px}
p.p3 {margin: 0.0px 0.0px 0.0px 12.0px; line-height: 18.0px; font: 12.0px Helvetica; color: #011892}
p.p4 {margin: 0.0px 0.0px 0.0px 12.0px; line-height: 18.0px; font: 12.0px Helvetica; color: #011892; min-height: 14.0px}
p.p5 {margin: 0.0px 0.0px 0.0px 12.0px; line-height: 15.0px; font: 12.0px Helvetica; color: #011892}
p.p6 {margin: 0.0px 0.0px 0.0px 12.0px; line-height: 14.0px; font: 12.0px Helvetica; color: #011892}
p.p7 {margin: 0.0px 0.0px 0.0px 0.0px; line-height: 14.0px; font: 12.0px Helvetica; color: #000000; min-height: 14.0px}
p.p8 {margin: 0.0px 0.0px 0.0px 0.0px; line-height: 14.0px; font: 12.0px Helvetica}
p.p9 {margin: 0.0px 0.0px 0.0px 0.0px; line-height: 14.0px; font: 12.0px Helvetica; min-height: 14.0px}
p.p10 {margin: 0.0px 0.0px 0.0px 0.0px; font: 11.0px Menlo}
p.p11 {margin: 0.0px 0.0px 0.0px 0.0px; font: 11.0px Menlo; min-height: 13.0px}
p.p12 {margin: 0.0px 0.0px 0.0px 0.0px; font: 11.0px Menlo; color: #008f00}
span.s1 {color: #000000}
span.s2 {font-variant-ligatures: no-common-ligatures; color: #0433ff}
span.s3 {font-variant-ligatures: no-common-ligatures}
span.s4 {font-variant-ligatures: no-common-ligatures; color: #3495af}
span.s5 {font-variant-ligatures: no-common-ligatures; color: #000000}
span.s6 {font-variant-ligatures: no-common-ligatures; color: #008f00}
</style>
</head>
<body>
<p class="p1">On 2016-08-26 15:39:05 +0000, Félix Cloutier via swift-evolution said:</p>
<p class="p2"><br></p>
<p class="p3">Hi all,</p>
<p class="p4"><br></p>
<p class="p3">Currently, a function that throws is assumed to throw anything. There was a proposal draft last December to restrict that. The general idea was that you'd write, for instance:</p>
<p class="p4"><br></p>
<p class="p4"><br></p>
<p class="p3">enum Foo: ErrorProtocol {</p>
<p class="p3"> case bar</p>
<p class="p3"> case baz</p>
<p class="p3">}</p>
<p class="p4"><br></p>
<p class="p3">func frob() throws Foo {</p>
<p class="p3"> throw Foo.bar // throw .bar?</p>
<p class="p3">}</p>
<p class="p4"><br></p>
<p class="p3">If you `catch Foo` (or every case of Foo), now that the compiler can verify that your catch is exhaustive, you no longer have to have a catch-all block at the end of the sequence.</p>
<p class="p4"><br></p>
<p class="p3">This impacts the metadata format and has implications on resilience, which leads me to believe that the discussion could qualify for the phase 1 of Swift 4. If this is the case, I'd be interested in pulling out the old discussions and seeing where we left that at.</p>
<p class="p5">Félix<span class="Apple-converted-space"> </span></p>
<p class="p4"><br></p>
<p class="p6">_______________________________________________</p>
<p class="p6">swift-evolution mailing list</p>
<p class="p6">swift-evolution@swift.org</p>
<p class="p6">https://lists.swift.org/mailman/listinfo/swift-evolution</p>
<p class="p7"><br></p>
<p class="p7"><br></p>
<p class="p8"><span class="s1">H</span>i,</p>
<p class="p9"><br></p>
<p class="p8">Shouldn't the compiler be able to infer the types thrown, and thus whether all types have been thrown? The general idea being that the following would be valid:</p>
<p class="p9"><br></p>
<p class="p10"><span class="s2">enum</span><span class="s3"> Foo: </span><span class="s4">Error</span><span class="s3"> {</span></p>
<p class="p10"><span class="s3"><span class="Apple-converted-space"> </span></span><span class="s2">case</span><span class="s3"> bar</span></p>
<p class="p10"><span class="s3"><span class="Apple-converted-space"> </span></span><span class="s2">case</span><span class="s3"> baz</span></p>
<p class="p10"><span class="s3">}</span></p>
<p class="p11"><span class="s3"></span><br></p>
<p class="p12"><span class="s2">func</span><span class="s5"> hello() </span><span class="s2">throws</span><span class="s5"> { </span><span class="s3">// inferred to throw only "Foo.bar"</span></p>
<p class="p10"><span class="s3"><span class="Apple-converted-space"> </span></span><span class="s2">throw</span><span class="s3"> </span><span class="s4">Foo</span><span class="s3">.</span><span class="s4">bar</span></p>
<p class="p10"><span class="s3">}</span></p>
<p class="p11"><span class="s3"></span><br></p>
<p class="p12"><span class="s2">func</span><span class="s5"> world() </span><span class="s2">throws</span><span class="s5"> { </span><span class="s3">// inferred to throw only "Foo.baz"</span></p>
<p class="p10"><span class="s3"><span class="Apple-converted-space"> </span></span><span class="s2">throw</span><span class="s3"> </span><span class="s4">Foo</span><span class="s3">.</span><span class="s4">baz</span></p>
<p class="p10"><span class="s3">}</span></p>
<p class="p11"><span class="s3"></span><br></p>
<p class="p12"><span class="s2">func</span><span class="s5"> galaxy() </span><span class="s2">throws</span><span class="s5"> { </span><span class="s3">// inferred to throw only "Foo.baz"</span></p>
<p class="p10"><span class="s3"><span class="Apple-converted-space"> </span></span><span class="s2">do</span><span class="s3"> {</span></p>
<p class="p10"><span class="s3"><span class="Apple-converted-space"> </span></span><span class="s2">try</span><span class="s3"> </span><span class="s4">hello</span><span class="s3">()</span></p>
<p class="p10"><span class="s3"><span class="Apple-converted-space"> </span>} </span><span class="s2">catch</span><span class="s3"> Foo.</span><span class="s4">bar</span><span class="s3"> {</span></p>
<p class="p10"><span class="s3"><span class="Apple-converted-space"> </span></span><span class="s6">// ...</span></p>
<p class="p10"><span class="s3"><span class="Apple-converted-space"> </span>}</span></p>
<p class="p12"><span class="s5"><span class="Apple-converted-space"> </span></span><span class="s3">// catch is exhaustive, no catch-all clause needed</span></p>
<p class="p11"><span class="s3"></span><br></p>
<p class="p10"><span class="s3"><span class="Apple-converted-space"> </span></span><span class="s2">try</span><span class="s3"> </span><span class="s4">world</span><span class="s3">()</span></p>
<p class="p10"><span class="s3">}</span></p>
<p class="p11"><span class="s3"></span><br></p>
<p class="p12"><span class="s2">func</span><span class="s5"> universe() { </span><span class="s3">// all errors are handled, no 'throws' declaration needed</span></p>
<p class="p10"><span class="s3"><span class="Apple-converted-space"> </span></span><span class="s2">do</span><span class="s3"> {</span></p>
<p class="p10"><span class="s3"><span class="Apple-converted-space"> </span></span><span class="s2">try</span><span class="s3"> </span><span class="s4">galaxy</span><span class="s3">()</span></p>
<p class="p10"><span class="s3"><span class="Apple-converted-space"> </span>} </span><span class="s2">catch</span><span class="s3"> Foo.</span><span class="s4">baz</span><span class="s3"> {</span></p>
<p class="p10"><span class="s3"><span class="Apple-converted-space"> </span></span><span class="s6">// ..</span></p>
<p class="p10"><span class="s3"><span class="Apple-converted-space"> </span>}</span></p>
<p class="p12"><span class="s5"><span class="Apple-converted-space"> </span></span><span class="s3">// catch is exhaustive, no catch-all clause needed</span></p>
<p class="p10"><span class="s3">}</span></p>
<p class="p9"><br></p>
<p class="p8">Now for clarity one could add the type information as per your proposal, but wouldn't be necessary as the compiler would infer it itself.</p>
<p class="p9"><br></p>
<p class="p8">Either way a +1 from me, as the current model forces one to catch-all errors, even the ones you did not expect to be thrown. Thus potentially hiding programming errors.</p>
<p class="p9"><br></p>
<p class="p8">- Bouke</p>
</body>
</html>