My understanding try?was that when evaluating the expression following try?, it nilwill be returned if there is an exception, otherwise the return value of the function is returned.
When I run the following code:
guard let istream = InputStream(url: url),
let ambiguousObj = try? JSONSerialization.jsonObject(with: istream, options: []),
let jsonObj = ambiguousObj as? [[String: Any]] else {
throw ExportError.recoveredParseFailed
}
I get an error related to the second line above:
*** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '*** +[NSJSONSerialization JSONObjectWithStream:options:error:]: stream is not open for reading'
I understand how to fix the error. (I needed to call istream.open())
But can anyone help me understand why I try?did not catch the exception in this case?
source
share