[swift-evolution] do try catch?

王巍 onevcat at gmail.com
Mon Dec 7 08:36:07 CST 2015


The first (current) choice is better in fact.

With try closure out of the scope, you could not tell exactly which statement would throw. 
In your example, only `makeSandwich` would throw, so there is no need to mark `eatASandwich` with a `try`.

Current design follows minimal conception very well, you could get to know that only the `makeASandwich` would throw an error, which reduce a lot of noise when reading this code.


Best regards.
---
Sincerely, 
Wei Wang (王巍, @onevcat)
im.onevcat.com <http://im.onevcat.com/>
> 在 2015年12月7日,下午11:30,Don Arnel via swift-evolution <swift-evolution at swift.org> 写道:
> 
> Is there a reason this format was adopted for error handling:
> 
> do {
>     try makeASandwich()
>     eatASandwich()
> } catch Error.OutOfCleanDishes {
>     washDishes()
> } catch Error.MissingIngredients(let ingredients) {
>     buyGroceries(ingredients)
> }
> 
> rather than this format:
> 
> try {
>     makeASandwich()
>     eatASandwich()
> } catch Error.OutOfCleanDishes {
>     washDishes()
> } catch Error.MissingIngredients(let ingredients) {
>     buyGroceries(ingredients)
> }
> 
> The second format is much more intuitive, and reads easier IMO.
> 
> 
> _______________________________________________
> swift-evolution mailing list
> swift-evolution at swift.org
> https://lists.swift.org/mailman/listinfo/swift-evolution

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.swift.org/pipermail/swift-evolution/attachments/20151207/8b1092df/attachment.html>


More information about the swift-evolution mailing list