Forwarding an error in Swift

前端 未结 2 452
北恋
北恋 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条回答
  • 2020-12-12 08:35

    You don't need to catch them they will be thrown automatically as you marked your function with throws

    func func1() throws {
        try func2()
    }
    
    0 讨论(0)
  • 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()
    }
    
    0 讨论(0)
提交回复
热议问题