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!

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

iOS Closures in Swift Error Handling and Memory Management Rethrowing An Error

Roland Schützenhofer
Roland Schützenhofer
4,311 Points

Is this really safe?

I'm not sure if it is really safe to use the "rethrows" method. In the code below the compiler doesn't show an error, but in approximately 50% of executions this will produce a runtime error.

var randomNumber = customRandomNumber(from: 0, to: 2) var number: Int if randomNumber > 1 { number = 0 } else { number = 1 }

10.apply(number) { $0/$1 }