官术网_书友最值得收藏!

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.

主站蜘蛛池模板: 竹山县| 七台河市| 安顺市| 宜丰县| 黄陵县| 洛南县| 平度市| 永登县| 青铜峡市| 溧阳市| 云阳县| 信丰县| 宜春市| 宣武区| 顺义区| 彰化市| 屯留县| 武强县| 库伦旗| 普兰县| 双桥区| 洛宁县| 抚顺县| 贺兰县| 夹江县| 海阳市| 连州市| 大洼县| 虞城县| 西藏| 伽师县| 松溪县| 鄂尔多斯市| 华阴市| 仁化县| 乐都县| 五河县| 正安县| 东光县| 铅山县| 长丰县|