2016-01-13 330 views
0

當我不想處理錯誤,並希望錯誤被傳遞時,是否有比捕獲錯誤並再次拋出錯誤更好的方法?拋出拋出的錯誤

func myThrowingFunction() throws { 
    do { 
    try anotherThrowingFunction() 
    } catch(let error) { 
    throw error 
    } 
} 

在其他語言中,你可以這樣做:

func myThrowingFunction() throws { 
    anotherThrowingFunction() 
} 
+0

也許這個:http://stackoverflow.com/questions/33350360/forwarding-an-error-in-swift – Moritz

+1

非常感謝Eric,我找不到它 – Daniel

回答

1

在其他語言中,你可以這樣做:

func myThrowingFunction() throws { 
    anotherThrowingFunction() 
} 

所以太斯威夫特:

func myThrowingFunction() throws { 
    try anotherThrowingFunction() 
}