Tutorial: Catching Exceptions to Help Debug Before Your Application Explodes

This tutorial uses Xcode 4.2

One of the major problems iOS developers have is being able to work out where an exception is thrown. There are several ways that you can make debugging easier on yourself. Below is a couple of tips.

Global Breakpoint

One handy technique is to set a global breakpoint on all exceptions raised. This can be done as follows:

Options For New Exception

Open Xcode and launch any project – it doesn’t matter what it is.

On the left hand sidebar select the sixth tab (the breakpoints navigator), and click add in the lower left hand corner.

Choose “Add Exception Breakpoint..” from the options. In the pop up make sure the drop down says “On Throw” and click done.

It will now have added a new breakpoint. Lets make this global so that it is on every project you open.

Right click the “All Exceptions” breakpoint and choose “Move Breakpoint To” and then “User”.

Thats it! Now whenever an exception is thrown you will see the exact line of code that causes it.

Backtracing

When you do encounter an exception and it pops up in the log it will have on the bottom line “(gdb)” and then a cursor. If you type “bt” here without the speech marks it will give you a list of what was executed before the exception was raised. This can help solve a lot of issues.

We hope this helped you out solving your problems!

Leave a Comment