Avoiding Nested Try/Catch Blocks
Michael Long ∙ 3 min read![]() ∙ View on MediumAvoiding Nested Try/Catch BlocksA common pattern in Swift that's easy to avoid.![]() This is a quick one, and a departure from the Navigator series, but I've seen this anti-pattern a lot and just thought I'd mention how easy it is to avoid. When making API calls, it's a fairly common practice to want to map any errors that might occur into a more finite set of "known" errors that are easier to handle. An example might be: public enum NetworkError: Error { case data case server case status(Int) case validation(String) } Note the "data" error we want to display in case our data is corrupted or in an unknown format. Nested Try/CatchWith that… Continue reading This is a member-only story and can only be read on Medium. Sent to sikubaycom.s3cr3tz@blogger.com by Michael Long on Medium Unsubscribe from this newsletter or unsubscribe from all newsletters from Medium Manage your email settings Medium, 548 Market St, PMB 42061, San Francisco, CA 94104 Careers·Help Center·Privacy Policy·Terms of service |