4

私はこれをやりたいと思っています:

do {
    let result = try getAThing()
} catch {
   //error
}

do {
    let anotherResult = try getAnotherThing(result) //Error - result out of scope
} catch {
    //error
}

しかし、これしかできないようです:

do {
     let result = try getAThing()
     do {
          let anotherResult = try getAnotherThing(result) 
     } catch {
          //error
     }
} catch {
     //error
}

resultdo/catch ブロックをネストすることなく、不変をスコープ内に保持する方法はありますか? guardif/else ブロックの逆としてステートメントを使用する方法と同様に、エラーを防ぐ方法はありますか?

4

1 に答える 1