0

I keep getting into the situation where I'm writing the catch statement of do { ...} catch ... {} block and I don't know what errors might be thrown by the function/method I'm calling. Is there any way to get a list ErrorTypes that may be thrown aside from digging into the code?

I'm using Xcode 7.3 Beta 5

With Swift 2.0, it looks like enums are the preferred way of defining errors. I'm using several non-Apple libraries and some take advantage of this and it'd be nice to have autocomplete list possible error types that could be thrown.

donut
  • 9,427
  • 5
  • 36
  • 53
  • 4
    What method is throwing the error? If it is an iOS SDK method, they all throw `NSError` objects. See [How get the list of errors thrown by a function?](http://stackoverflow.com/q/34877027/2415822) – JAL Mar 21 '16 at 18:57
  • With Swift 2.0, [it looks like `enum`s are the preferred way](https://developer.apple.com/library/prerelease/ios/documentation/Swift/Conceptual/Swift_Programming_Language/ErrorHandling.html#//apple_ref/doc/uid/TP40014097-CH42-ID508) of defining errors. I'm using several non-Apple libraries and some take advantage of this and it'd be nice to have autocomplete list possible error types that could be thrown. – donut Mar 21 '16 at 19:23
  • There's really no way to get a list of `ErrorType`s thrown by a function. `ErrorType` is a protocol that objects an enums can conform to (`NSError` conforms to `ErrorType`, and you need to check the error code returned to handle specific errors). – JAL Mar 21 '16 at 19:26
  • 1
    But I'd think that this is something Xcode could figure out. It could look at the call chain and see all the possible enums thrown and use that for autocomplete. That's what I'm hoping for. But I guess it's not built into Xcode. – donut Mar 21 '16 at 19:31

0 Answers0