[swift-evolution] [Discussion] "try" for function that does not throw

Haravikk swift-evolution at haravikk.me
Thu Jul 7 14:10:57 CDT 2016


> On 7 Jul 2016, at 19:41, David Sweeris via swift-evolution <swift-evolution at swift.org> wrote:
> 
> 
>> On Jul 7, 2016, at 12:58, Vladimir.S via swift-evolution <swift-evolution at swift.org> wrote:
>> 
>> I didn't expect this is allowed(with warning):
>> 
>> try print("foo")
>> 
>> (Swift Ver. 3.0 (Jun 20, 2016))
>> 
>> Do we really need to allow 'try' for functions that does not throw exceptions?
> 
> What's the harm?

None as such, but you argue that a warning in this case is safer; for example, if you had two similar functions, one of which throws, then typing try on the wrong one will produce a warning that can alert you to the mistake, while the current behaviour never will (in fact the presence of try may make the error harder to spot, as it *looks* correct).

So yeah, I'm surprised this is the case, should probably be turned into a warning.


More information about the swift-evolution mailing list