3lvis / DATAStack

100% Swift Simple Boilerplate Free Core Data Stack. NSPersistentContainer
Other
214 stars 44 forks source link

Change throws from Notifications #86

Closed Sorix closed 8 years ago

Sorix commented 8 years ago

Throws from notifications is very hard to debug -- XCode 8 doesn't show exact place where exception was raised, you see only EXC_BAD_ACCESS.

Example throw:

   func backgroundContextDidSave(notification: NSNotification) throws {
        if NSThread.isMainThread() && TestCheck.isTesting == false {
            throw NSError(info: "Background context saved in the main thread. Use context's `performBlock`", previousError: nil)

My main goal is to give an ability to developer to catch a bug with correct error message and full method call history (throw won't give call stack correctly).

I don't know if throw from notification will crash binary on release build, on debug build it crashes.

My proposals:

  1. Change notifications' throws to asserts, so you can see error message, exact place and correct view in debugger. Assert will be shown only on debug build, so in release mode application will try continue work without guarantees, may be Core Data won't raise an exception and all will be okay.
  2. Change notifications' throws to fatalErrors, so application will terminate in any way in release & debug mode.
3lvis commented 8 years ago

Using throw for error handling is best practice. Using something else would be a regression more than an improvement in my opinion.

https://developer.apple.com/library/content/documentation/Swift/Conceptual/Swift_Programming_Language/ErrorHandling.html