[swift-evolution] do try catch?

Slava Pestov spestov at apple.com
Mon Dec 7 13:09:37 CST 2015


Hi Don,

This is just my opinion, but I prefer the explicit 'try' on each statement that can throw, because then it is easier to see where all the early returns are from a function, in case any resources have to be cleaned up with a 'defer'.

Slava

> On Dec 7, 2015, at 6:30 AM, Don Arnel via swift-evolution <swift-evolution at swift.org> wrote:
> 
> 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/1fee6278/attachment.html>


More information about the swift-evolution mailing list