u16suzuの blog

日々学んだことのメモブログです。

例外を投げるclosure

() throws ->(String) in と書くと例外を投げるクロージャを定義できる

enum MyError : ErrorType {
    case Hoge
}

let c = {() throws ->(String) in
    throw MyError.Hoge
}
        
do {
    try c()
}
catch {
    print( "\(__FUNCTION__): L\(__LINE__)")
}