I have an app that uses WatchConnectivity to send information from an iPhone app to an Apple Watch app. In some cases, I'm using updateApplicationContext(_:), which throws. This isn't very relevant to the question, but I'm mentioning it so I can provide a code example below.
I'm interested in finding out reasons why this is failing in production, so that I can handle errors in the future. More generally, I want to improve my error handling throughout any apps I build, so I'm trying to figure out the best way to find out which errors are being thrown in different scenarios in production so I can address those.
Obviously, it is a bad idea to ship an app with fatalError in it, but I thought maybe that would at least be a way I can get this data to show up with crashes in Xcode using this code:
do {
try WCSession.default.updateApplicationContext(phoneInfo)
} catch(let error) {
// This actually does fail in the wild... I'd like to know the reason or reasons
fatalError(error.localizedDescription)
}
However, I know from other more severe cases experimenting with fatalError in production when I was a newer developer that I don't actually get the localizedDescription with the crash in the Xcode crash logs. I'm assuming this only writes the localizedDescription out to the console, but not to crash logs.
What is a good way that I can get information about errors that are thrown in production? I'd like to avoid using third party frameworks.