Is there any way how we can specify a breakpoint to stop on all 'throw' statements? (symbolic breakpoint)
guard let id = UInt(idString),
let changeset = UInt(changesetString),
let uid = UInt(uidString)
else {
throw OSMVectorMapDescriptionError.ElementAttributeConversionError(element: xmlNode, attributeº: nil)
}
Select all the methods using ctrl . Right click and select Toggle Method Breakpoint .
To set a breakpoint in source code: Click in the far left margin next to a line of code. You can also select the line and press F9, select Debug > Toggle Breakpoint, or right-click and select Breakpoint > Insert breakpoint. The breakpoint appears as a red dot in the left margin.
To set a function breakpoint, on the Run view right-click inside the Breakpoints section, then choose Add Function Breakpoint and enter the name of the function on which you want to break execution.
In the Breakpoint navigator, click the Add button (+) in the lower-left corner, and choose Symbolic Breakpoint. Enter the object and symbol in the Symbol field, using the format of the example text. The debugger pauses when the app or your code calls the symbol you specify.
First thing to keep in mind is that errors thrown in Swift are not exceptions, just errors (NSError
, whatever based on ErrorType
, ...).
Second thing is, don't use try!
unless you're damn sure it will not crash or if crash is what you really want.
Don't mix symbolic breakpoint with exception breakpoint. Different beasts.
Back to your question ...
throw
is not a symbol, thus symbolic breakpoint doesn't work for you. But there's a way ...
(lldb)br s -E swift
-E <language> ( --language-exception <language> )
Set the breakpoint on exceptions thrown by the specified language
(without options, on throw but not catch.)
... this is little bit misleading, because thrown errors are not exceptions. Keep this in mind. When you try to set exception breakpoint in Xcode, there's no Swift. Probably the main reason is that thrown errors are not exceptions and they didn't figure out where to put it yet (who knows).
Add it manually
Set a breakpoint somewhere in your code, when execution pauses, just type br s -E swift
in LLDB prompt and then continue.
Add it automatically
Set a breakpoint somewhere in your code in this way ...
... and toggle it (on/off) when you do want to stop on throw
.
Symbolic breakpoint
When you do use already mentioned br s -E swift
you are going to find that there's symbol for throw
. Actually it's not throw
, but swift_willThrow
. Feel free to set symbolic breakpoint in this way ...
... I do not recommend this way for now, because it can be changed in the future. But if it's enough for now, why not.
You can share your breakpoint across Xcode projects like this ...
... secondary click, Move Breakpoint To, User. Breakpoint will be visible in all Xcode projects.
When you hit breakpoint, you'll end up in something like this ...
... and you have to select previous stack frame to see where the error was thrown ...
Just found an alternative in Xcode 8.3: there is a "Swift Error Breakpoint" option in the menu for adding new ad-hoc breakpoints:
If you right-click the newly created breakpoint, you can even specify a particular Error
-conforming type to break on.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With