上QQ阅读APP看书,第一时间看更新
Multiple catch statements
In the preceding example, you will notice that we've created a catch statement, and inside, we used a switch statement to cover all cases of error. This is a correct way, but for your reference, we have another way to do this. Consider the following:
catch SignUpUserError.InvalidFirstOrLastName{ } catch SignUpUserError.InvalidEmail{ } catch SignUpUserError.WeakPassword{ } catch SignUpUserError.PasswordsDontMatch{ }
After the do statement, you can list catch statement with the type of error that this statement will catch. Using this method has a condition that the catch statements should be exhaustive, which means it should cover all types of errors.