Xcode throws an exception in Main () in iOS 8 with a "all exceptions" breakpoint

I am using Xcode 6 (GM, I have not downloaded beta) and I am developing applications for iOS 7+. For all my projects, I just opened the same projects as before in Xcode 5.

In the Breakpoint navigator, I enabled the All Exceptions breakpoint. It is set to Break: On Throw . Now, every time I run my application (whether on the device or in the simulator), it stops execution on the return UIApplicationMain(argc, argv, nil, NSStringFromClass([AppDelegate class])); line return UIApplicationMain(argc, argv, nil, NSStringFromClass([AppDelegate class])); in the main() function.

If I press Play to continue the program twice, the program works fine. Thus, this does not stop me from working, but I still have to manually execute each time and reset my editors.

I like the behavior I set in Xcode (moving the current editor to where the execution is paused), and having this All Exceptions breakpoint is an important IMO. (Therefore, I do not want to change them)

By running the same code, with the same environments, for iOS 7 target (again, a device or a simulator), an exception is not thrown.

Is it possible to understand what might cause this strange behavior?

+44
objective-c xcode ios8 xcode6
Sep 30 '14 at 17:51
source share
4 answers

As stated in the comments, you should turn off C ++ exception catching by editing the All Exceptions breakpoint.

To do this, right-click on the breakpoint and change the Exception from All to Objective-C :

change All to Objective-C

Exceptions in C ++ code are part of the normal functionality of the application. However, the control point of the exception does not capture the unhandled, but all exceptions that occur, even when they are processed correctly later, therefore, the execution is stopped.

+92
Nov 20 '14 at 10:30
source share
β€” -

TL; DR; In my case, the cause of the problem was missing fonts.

I also had this problem. While @Johnnywho is right, leaving an Exception point only for Objective-C stops unwanted behavior, she still doesn't explain what is the real reason why she runs without exception on iOS7 and why this only happens on some projects.

That's why I continued and reviewed one of my projects in which I had this problem, until the moment when I could find the reason. I believe there may be several reasons for this behavior, but in my case there were no custom fonts.

A quick way to test it:

  • Launch a new project with one view.

  • Enable breakpoint in all exceptions, including C ++ (Breakpoints / + / Add Exception Breakpoint)

  • Drag and drop some custom font into the project (enable copying and check the target to add it)

  • Add a label to the view in the main view controller

  • Choose your own font for your label (on Xcode 6+, it should appear in the font picker as soon as you drag it into the project).

  • Launch the application and confirm that you see the label in your custom font (it seems that we no longer need to add the font file name in Info.plist for the "Fonts provided by the application" key if the custom font was used in the xib storyboard of the application).

  • Now remove the custom font from your project (either by deleting the target relationship, or by deleting it in the target settings / Build Phases / Copy Bundle Resources)

  • Remove the application from your device or sim (to remove the font file from the application package)

  • Product / Cleaning

  • Launch the application again (now the label still has a link to a custom font, but the application does not have a file for it). You should notice a cryptic exception if you run iOS8.

  • Launch the application on the device with iOS7 or sim with iOS7 (for this you will need to change iOS for iOS7). Although the custom font is not displayed on the label, there will be no exceptions.

  • Add the font file back to the target, and the breakpoint no longer stops.

So, my conclusion is that on iOS8 the missing fonts cause a C ++ exception, but on iOS7 they are not, so the breakpoint trigger.

A similar exception (and a breakpoint trigger) can also be caused by an incorrectly written font file name in the Info.plist file under the key "Fonts provided by the application."

+27
Mar 03 '15 at 16:25
source share

Just summed up the previous answers that helped me fix this.

Problem. When you add your own font and then, apparently, delete (replace) it, somewhere in the project its link still remains, and the breakpoint stops several times when the breakpoint stops in C ++ lib in iOS 8.

Decision

1) Find in the project and delete (replace) all links to these fonts. May be in some knives, submodules, etc.

2) If you cannot fix it everywhere (for example, to use read-only libs), or if the problem still exists after solution 1, add these old fonts back to the project

3) Ignore it - this is C ++ lib, so change the breakpoint exception from "All" to "Objective-C" only

+3
Jul 02 '15 at 8:53
source share

Xcode 9, exceptions sometimes appear, but iOS catches it gracefully. It will help

enter image description here

enter image description here

source

for my case, it was a custom attribute in nib

+1
Dec 05 '17 at 9:23
source share



All Articles