Suppose I’m writing a function that reads from a file. This function doesn’t resort to standard library, but I’d like it to behave like the standard library’s when failing, which may mean throwing an exception.
How do I make that exception similar to what the standard libray would have thrown, so that the caller can handle it the same way? Or, if this not desirable, why?
It seems that there is no way of knowing what a specific function can throw, either programmatically or from Apple’s documentation.
Is there a list of standard library exceptions?
Currently, I’m down to defining my own enum error cases:
enum FileError: Error {
case fileNotFound(at path: String)
case writingToReadOnlyFile(at path: String)
}
I find this redundant.