How to throw the same errors as standard library does, in Swift?
<p>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.</p>

<p>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?</p>

<hr>

<p>It <a href="https://stackoverflow.com/questions/34877027/how-get-the-list-of-errors-thrown-by-a-function">seems</a> that there is no way of knowing what a specific function can throw, either programmatically or from Apple’s documentation.</p>

<p>Is there a list of standard library exceptions?</p>

<p>Currently, I’m down to defining my own enum error cases:</p>

<pre><code>enum FileError: Error {
    case fileNotFound(at path: String)
    case writingToReadOnlyFile(at path: String)
}
</code></pre>

<p>I find this redundant.</p>