Swift version: 5.1
Xcode has a few special breakpoint types, accessed by going to the breakpoint navigator (Cmd+8) then clicking + in the bottom-left corner. One of the options in that menu is Swift Error Breakpoint, and it allows Xcode to pause when Swift errors are thrown.
Swift error breakpoints are different from catching errors normally – in fact, the two complement each other nicely. If you’re calling someone else’s code (e.g. Apple’s) and that code throws an error, a Swift error breakpoint won’t halt on that. Instead, it will halt on errors thrown by your own code, i.e. wherever you use a
Swift error breakpoints are helpful because of the way Swift errors propagate – sometimes an error might be throw five methods deep in your code, then bubble upwards and upwards until they get handled. Once you enable the error breakpoint, Swift will pause where the error is thrown, so you don’t need to dig through your code.
SAVE 20% ON iOS CONF SG The largest iOS conference in Southeast Asia is back in Singapore for the 5th time in January 2020, now with two days of workshops plus two days of talks on SwiftUI, Combine, GraphQL, and more! Save a massive 20% on your tickets by clicking on this link.
Available from iOS
This is part of the Swift Knowledge Base, a free, searchable collection of solutions for common iOS questions.