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.
Available from iOS
Did this solution work for you? Please pass it on!
Other people are reading…
About the Swift Knowledge Base
This is part of the Swift Knowledge Base, a free, searchable collection of solutions for common iOS questions.
Want to build macOS apps?
Hacking with macOS delivers 18 awesome projects that teach you macOS development in no time – take control of your desktop today!