Ios libc++;abi.dylib:以NSException类型的未捕获异常终止;如何捕获异常

Ios libc++;abi.dylib:以NSException类型的未捕获异常终止;如何捕获异常,ios,core-data,swift3,Ios,Core Data,Swift3,我有一段简单的代码,我正试图捕捉异常 do { let result = activity_record.setValue(name, forKeyPath: "key_TRANSACTION_NAMEs") } catch { print("Could not save record error") // Display an error that record could not be saved let ale

我有一段简单的代码,我正试图捕捉异常

do {
        let result = activity_record.setValue(name, forKeyPath: "key_TRANSACTION_NAMEs")
    }
    catch {
        print("Could not save record error")
        // Display an error that record could not be saved
        let alert = UIAlertController(title: "Error", message: "Could not save record",  preferredStyle: UIAlertControllerStyle.alert)
        alert.addAction(UIAlertAction(title: "Ok", style: UIAlertActionStyle.default, handler: nil))
        self.present(alert, animated: true, completion: nil)
    }
当我运行此代码时,应用程序崩溃,错误代码为-

libc++abi.dylib: terminating with uncaught exception of type NSException
我无法捕捉错误并在代码中优雅地处理它。你能推荐解决这个问题的最佳方法吗?我使用的是CoreData,IOS目标9.3 Swift 3,XCode 8。“key\u TRANSACTION\u NAMEs”故意输入错误以测试代码(捕捉异常)

我在AppDelegate中使用以下命令获取managedcontext(databaseContext)

//标记:-实用程序例程 lazy var applicationdocuments目录:URL={ 让URL=FileManager.default.URL(对于:.documentDirectory,在:.userDomainMask中) 返回URL[url.count-1] }()

从Lajos身上获取动力;我应该为此函数返回什么(NSString)

extension NSObject {
    func setValue(anObserver: NSObject!,
              forKeyPath keyPath: String!,
              options: NSKeyValueObservingOptions,
              context: UnsafeMutablePointer<Void>) -> NSString! {
    return
    }
}
扩展对象{ func setValue(anObserver:NSObject!, forKeyPath键路径:字符串!, 选项:NSKeyValueObservingOptions, 上下文:UnsafeMutablePointer)->NSString{ 返回 } }
问题是:使用setValue返回什么?是否需要NSString作为返回?NSString将包含什么?我注意到您需要一个结果。但在什么情况下需要什么样的结果、什么样的数据?问题是:使用setValue返回什么?是否需要NSString作为返回?NSString将包含什么?我注意到您需要一个结果。但在什么情况下,您需要什么样的结果和数据?
extension NSObject {
    func setValue(anObserver: NSObject!,
              forKeyPath keyPath: String!,
              options: NSKeyValueObservingOptions,
              context: UnsafeMutablePointer<Void>) -> NSString! {
    return
    }
}