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

iOS

Samuel Yanez
Samuel Yanez
27,790 Points

Why Swift functions don't specify the type of errors they throw?

After watching the videos on Swift Error Handling, I'm wondering why Swift functions don't specify the type of errors they throw? Instead, we need to figure out what different kinds of errors can occur in the trying functions using different catching statements.

Wouldn't it be better just to specify the type of error in the function declaration, similar to what Java and other languages do?

1 Answer

Michael Hulet
Michael Hulet
47,912 Points

I love Swift, but in my opinion, this is a deficiency of the language. That being said, it was a deliberate design decision. You can read about the rationale behind it on its discussion/proposal page in the Swift repository