How to handle run time exceptions in Swift

I am working on a swift based iOS application. I am working with Swift 4.2 and Xcode 11.3.1. I want to implement the try catch exception handling for all the major functions irrespective of whether the function 'throws', so that I can get all the exceptions which are occurring in the application to any user at run time. I am planning to log all such run time exceptions in the text file on device and then upload it to my backend server for analyzing issues.

I have already tried to do this, but it seems Swift is not providing way to handle all the run time exceptions without throws. 

Is there a way, I can achieve the exception logging which I have mentioned above? 

I will appreciate any help.
The term exception is commonly used to refer to three different things:
  • Swift errors — Swift’s error throwing facility looks like an exception mechanism but it is not. For a good introduction to the philosophy behind this, see ErrorHandlingRationale.

  • Language exceptions — On modern platforms [1], Objective-C and C++ share a common exception mechanism. For example, if you try to add a nil value to an NSMutableArray, this is what gets thrown.

  • Machine exceptions — These exceptions are raised by the hardware itself, for example, if you try to access a NULL pointert. You can catch these in various ways (Mach exception handling, BSD signals) but it’s a very tricky business.

These different mechanisms are transparent to each other. For example, if you set up a Swift error handler and the code you call throws an language exception, the Swift error handler won’t be invoked.

So, what sort of exceptions do you want to catch?

Share and Enjoy

Quinn “The Eskimo!” @ Developer Technical Support @ Apple
let myEmail = "eskimo" + "1" + "@apple.com"

[1] Everything exception 32-bit Intel on macOS.
How to handle run time exceptions in Swift
 
 
Q