Many try in single do { ... } catch { ... }


Is a good (common) strategy to make several try attempts in single do { ... } catch { ... } statement?

do {
    let sever = try connect()
    let data = try
    try server.close()
} catch ServerError {
    // server
} catch ReadError {
    // read
} catch {
    // other

That depends on the flow: Often, it only makes sense to use a single "do", because steps build on top of each other.

In other words, if connect() and are independent and you don't want the failure of one method to interrupt the other – your example isn't the right approach, since if connect() throws an error, control will be transferred to catch. (The program will not proceed further in the do statement). Otherwise, like @tino noted, it is the right way to go.