【发布时间】:2015-10-05 15:47:45
【问题描述】:
我使用 Martin R 的答案在 Swift 中打印 NSSetUncaughtExceptionHandler。
How should I use NSSetUncaughtExceptionHandler in Swift
func exceptionHandler(exception : NSException) {
let alert = UIAlertController(title: "Exception", message: "\(exception)", preferredStyle: .Alert)
self.presentViewController(alert, animated: true, completion: nil)
print(exception)
print(exception.callStackSymbols)
}
但是如何在 UIView 中显示消息。喜欢这个
因为我收到一条编译器错误消息,说“C 函数指针只能由对 'func' 的引用或文字闭包形成。”
Handling unhandled exceptions and signals 由 Matt Gallagher 在 Cocoa with Love 撰写。
【问题讨论】:
-
你试过 exception.name 或 exception.reason 吗?
-
@Horst,我想在屏幕上显示消息,用户可以捕获并发回。
-
你没有显示你的整个代码
-
@newacct 我是 Swift 新手,大约只有 1 年。我正在尝试将 Matt 编写的代码从 ObjC 转换为 Swift。它可以编译,但不能运行。 'int retVal = UIApplicationMain(argc, argv, nil, nil);' 行中 main.m 中的错误消息 'Thread 1: singal SIGABRT'
-
@charles.cc.hsu:我很困惑。你不是说你有编译错误吗?
标签: ios swift exception uiview