ずばりこれ。
NSSetUncaughtExceptionHandler(_:) - Foundation | Apple Developer Documentation
swiftのcatchで拾えないものもこちらでハンドルできる。
AppDelegate等に入れておく。
func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplicationLaunchOptionsKey: Any]?) -> Bool { // Override point for customization after application launch. NSSetUncaughtExceptionHandler { exception in print(exception) fatalError() // 適当な処理の後落とす } return true }
ただ処理を継続しようとしても落ちるので、fatalError
等できちんと落とす。