Crashlytics reports that the following line is sometimes throwing a NSInternalInconsistencyException
:
let attrStr = try NSMutableAttributedString(
data: modifiedFont.data(using: String.Encoding.unicode,
allowLossyConversion: true)!,
options: [.documentType: NSAttributedString.DocumentType.html, .characterEncoding: String.Encoding.utf8.rawValue],
documentAttributes: nil)
Here I'm not as interested in why this happens (there's a 3 year old question about it) as I am in catching/handling this exception. I've tried to do it like this:
do {
let attrStr = try NSMutableAttributedString(
data: modifiedFont.data(using: String.Encoding.unicode, allowLossyConversion: true)!,
options: [.documentType: NSAttributedString.DocumentType.html, .characterEncoding: String.Encoding.utf8.rawValue],
documentAttributes: nil)
self.attributedText = attrStr
} catch {
self.attributedText = nil
self.text = text.stripHTML()
}
... but this is not working for some reason - the exception is still being reported.
Am I trying to catch it in the right way? Can it be caught at all? If not, what are my options?