Welcome to the Treehouse Community
Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.
Looking to learn something new?
Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.
Start your free trial
William Forbes
21,469 PointsDO Catch Statement questions/TRY statement
Hello, I know for the do catch statement this has to be exhaustive but what if code has several enumerations of the error type protocol? How does the function that contains the "throws" keyword know which enumeration to look to for the all of the error cases that need to be exhausted? Or when using a function that throws an error do I simply have to exhaust all cases on all enumerations of the Error Type protocol that exist in the code?
For example,
enum ErrorList1: ErrorType { case: Error#1 case: Error#2 }
enum ErrorList2: ErrorType { case: Error#3 case: Error#$ }
func doSomething(argument_1: String) throws { guard let something = argument_1 else { throw Errorlist1.case }
}
If I were to do a do/catch on this would the exhaustiveness required be just scoped to the ErrorList1 cases (Error#1, Error#2, default )? Or would it be required that I provide catchs the errors in ErrorList2 (Error#3, Error#4) as well?
Thanks!!