Forwarding an error in Swift

前端 未结 2 453
北恋
北恋 2020-12-12 08:03

Is there a better solution to forward a Swift error from one function to another?

In the moment, I\'m doing it like this:

enum Error:ErrorType{

             


        
2条回答
  •  -上瘾入骨i
    2020-12-12 08:50

    Yes: don't wrap it in a do ... catch block.

    func func2() throws{
         // proof something
         throw Error.Error1
    }
    
    func func1()throws{
         try func2()
    }
    

提交回复
热议问题