Try-Catch equivalent in Objective-C

objective-c

Solution

Although Objective-C does have an `@try`/`@catch`, it is not going to help you much. By the time you get to the `@catch`, the stack frame where the error happens would be gone.

What you need is to set up a breakpoint that breaks on exception: open the Breakpoint Navigator page (the second button from the right), and click [+] at the bottom of the navigator page. Choose "Add Exception Breakpoint...", then click [Done].

Now the program is going to break in the debugger each time that your program throws an exception.

Problem

I get an app crash in main.m in my app and have no idea why the error is happening because xcode doesn't show me where the crash occurs, it shows me that it crashes at return UIApplicationMain(argc, argv ...) which tells me nothing. Is there a way to have in Objective-C the equivalent of a try/catch in C++ to see exactly where the error is occuring?

Original source

Related problems