0

Declaration of the write method on Data class just says the method throws, but what types of errors?

The documentation says:

throws: An error in the Cocoa domain, if there is an error writing to the URL.

I want to surround the invocation of that method with a try {} catch {} clause and I'd prefer to catch specific errors and only catch the generic one if none of the specific ones were matched.

rmaddy
  • 314,917
  • 42
  • 532
  • 579
koleS
  • 1,263
  • 6
  • 30
  • 46
  • `Data` will call `NSData` methods behind the scene, and `NSData` being Objective C framework is capable to sending just one type of errors: `NSError`. – user28434'mstep Jun 10 '19 at 15:16
  • 1
    Swift follows the untyped error model, where methods can throw any errors they want, and they can change what errors they throw, at any time. Compare this with the checked exceptions in java. You won't be able to explicitly enumerate the types of errors to expect out of a function, but in exchange, library authors have more flexibility in adding new error types. – Alexander Jun 10 '19 at 15:16
  • When reviewing the duplicates, keep in mind that the list of Cocoa domain error codes is [documented](https://developer.apple.com/documentation/foundation/nserror/1448136-nserror_codes). – rmaddy Jun 10 '19 at 15:49

0 Answers0