How to Edit Swift Error Breakpoint

How to edit swift error breakpoint?

If you just create a Swift error breakpoint, it breaks on anything that conforms to ErrorType.

If you put something in Type, it'll only break when that type is thrown.

In the following:

enum MyError: ErrorType
{
case AnError
}

enum MyOtherError: ErrorType
{
case AnotherError
}

public func throwAnError()
{
do
{
throw MyOtherError.AnotherError
}
catch
{
print("Caught 1")
}

do
{
throw MyError.AnError
}
catch
{
print("Caught 2")
}
}

A break on Swift error will cause the debugger to stop on both throw lines. If you put MyError in the type field, the debugger will only stop on the second throw line.

How to set a breakpoint on all throws?

Just found an alternative in Xcode 8.3: there is a "Swift Error Breakpoint" option in the menu for adding new ad-hoc breakpoints:

swift error breakpoint

If you right-click the newly created breakpoint, you can even specify a particular Error-conforming type to break on.

custom type

Debugging in XCode: Exception Breakpoints

You don't have much control over where that breakpoint triggers. Once you've hit the breakpoint though, you can use the bt command to print the current stack trace.


EDIT: With the backtrace...

It looks like UIDocument's -saveToURL:forSaveOperation:completionHandler: method is the culprit. I've never used the class before, so I can't help too much. If you're calling that method anywhere in your code (like from a block?), you could also put a breakpoint there, in anticipation of the failure.

Always stop in App delegate after enabling All exceptions break point

Only enable Objective-C breakpoints.

To see the actual statement that is causing the error add an exception breakpoint:

  1. From the Main Menu Debug:Breakpoints:Create Exception Breakpoint.

  2. Right-click the breakpoint and set the exception to Objective-C. This will ignore other types of exceptions such as from C++. There are parts of the APIs that use exceptions such as Core Data (Apple is Special).

  3. Add an action: "po $arg1".

Run the app to get the breakpoint and you will be at the line that causes the exception and the error message will be in the debugger console.

Breakpoint example:

Sample Image

Swift 4 AppDelegate Thread 1: breakpoint 1.2 error

You've assumed this was an error but it's actually a debugging breakpoint. You inadvertently set a breakpoint which is easy to do. Where the line is green, it says breakpoint but does not say error.

To remove any breakpoints, click on the blue arrow seen in your screenshot. With the breakpoints removed, the code should run normally.

When only All Exceptions breakpoint is set, Xcode 7 always stop on app start

This breakpoint comes from an exception that was thrown by TFileDescriptorContext. All Exceptions halts also on C++ exceptions.

It gives you a good indication where the problem comes from. Take a look if all fonts that are listed in Info.plist are part of your application bundle.

"Normally" you are not interested in C++ exceptions when you are in Objective-C, so feel free to ignore them.

Edit: This problem has been discussed several times here on SO. Updating when I can find the posts again which might give you even a deeper insight.



Related Topics



Leave a reply



Submit