TLDR; how do I find out what errors a foundation method can throw so I can properly handle the error case?
The swift error handling documentation says you handle errors like this
enum VendingMachineError: ErrorType
{
case InvalidSelection
case InsufficientFunds(centsNeeded: Int)
case OutOfStock
}
do {
try vend(itemNamed: "Candy Bar")
// Enjoy delicious snack
} catch VendingMachineError.InvalidSelection {
print("Invalid Selection.")
} catch VendingMachineError.OutOfStock {
print("Out of Stock.")
} catch VendingMachineError.InsufficientFunds(let amountNeeded) {
print("Insufficient funds. Please insert an additional \(amountNeeded) cents.")
}
I want to do the same thing for CocaTouch classes like FileManager. However I can't find the errors that each method throws. I didn't see it in any documentation and as far as I'm aware this code isn't open source.
do {
let docsArray = try fileManager.contentsOfDirectoryAtPath(docsPath)
} catch FileManagerError.PathNotFound {
print("The path you selected does not exist.")
} catch FileManagerError.PermissionDenied {
print("You do not have permission to access this directory.")
} catch ErrorType {
print("An error occured.")
}
How are you supposed to handle all the error cases?