问题描述:

This question already has an answer here:

  • Error-Handling in Swift-Language

    12 answers

网友答案:

It doesn't have exception handling, and this discussion in the developer forum discusses why it may be so:

but keep in mind that Cocoa and Cocoa Touch traditionally don't intend for you to catch exceptions; they intend for you to not cause them to be thrown in the first place. Ordinary errors should be handled with optional types and inout NSError parameters; you should address any situation that causes an assertion to fail (which seems to be the only exception-throwing mechanism in Swift) by writing better code.

网友答案:

I believe that, as of today, Swift does not support this. It will most likely be added on future betas.

相关阅读:
Top