I'm new with Ios programming Objective-C language and my app was working great until suddenly stop working and get this error
Xcode show me a generic error and i want to know which function or instruction produce this error i couldn't find how to do this with Xcode i want just to point the problem where it may come from
This is the error i got :
Add Exception breakpoint
As shown in the image, select the 8th tab(Exception) and from the below add button, add the Exception Breakpoint. This will show the exact line of code from where the application crashes.
Add Exception breakpoint
How to create exception breakpoints in Xcode?
Exception breakpoints are a powerful debugging tool that remarkably
few people know about, so please read the following carefully and put
it into practice!
A regular breakpoint is on a line you specify and causes the debugger
to pause execution at that point so you can evaluate your program's
state. An exception breakpoint tells the debugger to pause whenever a
problem is encountered anywhere in your program, so you can evaluate
your program's state before it crashes.
Exception breakpoints are trivial to set up: go to the Breakpoint
Navigation (Cmd+8), then click the + button in the bottom left and
choose Add Exception Breakpoint. You can leave it there if you want
to, but it's preferable to make one further change to reduce
unnecessary messages: right-click on your new breakpoint, choose Edit
Breakpoint, then change the Exception value from "All" to
"Objective-C".
Please follow the below steps.
Run your project.
Related
I am making an app, and I am doing my first test right now that should just show the basic layout and a little functionality. I have of course found all the compile time and runtime errors that xcode has caught, and I assume there are at least a few bugs will just make the app act weirdly, but I want to fix those after the app has actually run. Unfortunately, I am getting a SIGABRT error. First off, I am not even using Main.storyboard or ViewController.swift, so that is not the issue. No broken segues. This is what the console says: Console message.
So first I thought I just had an array out of bounds exception ("NSRangeException"), but the thing is, I never used an NSArray (I did use normal arrays though, and I am not ruling out a range out of bounds exception there, but I want to know why the console is saying it is an NSArray. If it is something else, I obviously need to know). Here is a "Stack trace" (or at least I assume so) also which I saw as a suggestion to find and error on a similar question (it was objective-c though, and he actually had an NSArray). Here is the link: similar question I don't know how to trace that back to the source, but that what it looks like leading up to the error. Basically, why I am asking this question is:
If you can tell me that I am completely wrong about thinking I have an array out of bounds error and what it is instead, please do that.
If you agree with me in thinking that is likely the issue, please explain to me why the compiler would refer to it as an NSArray; as far as I know, these are two completely different data structures.
Without code is very hard help you.
But you can check where is the error with an exception breakpoint.
Click on the Breakpoint navigator tab (the tab selected in the image):
Then click on the plus button in the bottom and select Exception breakpoint:
After this, you can reproduce the issue and when the app crashes the debugger stop all at the line where is our (empty) nsArray.
I've set an "All Exceptions" exception breakpoint for my project. In Xcode 7, it mysteriously fires on launch in main.m, but there doesn't seem to be anything obviously wrong. On continuing, the app runs normally.
Even running the project in Xcode 6 now causes this breakpoint to fire.
I can't figure out what is causing this. The threads don't indicate anything specific to what the cause is.
Maybe it's some sort of font issue in the Storyboard or something? Does anyone know a fix?
NOTE: It's a C++ exception, not Objective-C. Perhaps due to missing fonts. Xcode throws an exception in Main() in iOS 8 with 'all exceptions' breakpoint
I have almost the identical problem in Xcode 7, as of beta 3. This workaround solved it for me.
Because it's a C++ exception, you can change your "All Exceptions" breakpoint to catch only Objective-C exceptions. Having done this, I no longer hit the mystery break on startup, and because I'm not writing C++, get 99% of the value of having the "All Exceptions" break point on.
Here's how:
Go to the breakpoints tab (View > Navigators > Show Breakpoint Navigator or ⌘7).
Right click on the All Exceptions breakpoint and "Edit Breakpoint..."
Change the Exceptions covered to Objective-C only.
I started seeing the same behaviour in my application using the shorthand dictionary initialisation #{ ...: ... } in the willFinishLaunchingWithOptions function.
The problem was solved by replacing it with dictionaryWithObjectsAndKeys instead. I'm not sure if this was specific to my case or if the compiler has some kind of a problem with the shorthand syntax, but it's worth checking out if you're using that syntax.
When i enable all exceptions breakpoint my app always stops in AppDelegate, but im able to continue the program execution, but its very annoying cause always takes me to the appdelegate. Any ideas why?
Only enable Objective-C breakpoints.
To see the actual statement that is causing the error add an exception breakpoint:
From the Main Menu Debug:Breakpoints:Create Exception Breakpoint.
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).
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:
If you're using Swift, or you want to have all the exceptions captured, you can change an option on All Exceptions to automatically continue after evaluating actions. Just find it in the Breakpoint Navigator and right/ctrl click the all Exceptions Breakpoint to edit it:
Then check the Options box:
Exceptions in C++ code common and normal. The exception breakpoint catches every raised exception even when they are being handled correctly. So if you don't specify Obj-C only you will notice that execution stops in a lot of seemingly random places. I run into this all the time with AVAudioPlayer especially.
Another thing to look out for are missing assets. I came across this question from another asker who seems to have also run into the same issue.
Xcode throws an exception in Main() in iOS 8 with 'all exceptions' breakpoint
Since I've upgraded from xcode 3.1 to xcode 4.2, when I debug a program and for some reason I get a SIGABRT error (i.e. calling a method of an object that doesn't exist) Xcode shows the error in the main function of the program, instead of the line that is generating the SIGABRT.
Maybe I'm missing some kind of configuration in the debugger or in xcode? any ideas?
I had the same problem for a long time and I found a solution just now. Don't know if it's the most kosher way, but at least it works for me. Basically you should create a global breakpoint (global meaning applying to all your projects).
Check out this blog post, and this tutorial on how to create symbolic breakpoints. I myself created an Exception breakpoint (it catches objc_exception_throw too) this way:
and then moved it to "User" breakpoints space:
Make sure that the scheme you are using has breakpoints active. You can turn them on by hitting the button next to the scheme selector.
http://bit.ly/zuTnpF
What did it for me, was something that I found here that has to do with creating NSZombies
I'll at least copy the highlights:
Go to your project in Xcode 4
Environment variables can be set up in the Scheme editor (find Product -> Edit scheme… in menu bar):
Name the variable as NSZombieEnabled and set its value to YES.
Run your app in Debug mode. You likely get a … message sent
to deallocated instance… message and the debugger stops at the line in error. This information leads to the problem.
When ready, disable NSZombieEnabled by changing YES to NO.
When I crash (for reasons I understand; that's not the problem) when I try to do something Cocoa isn't okay with, such as calling a method that doesn't exist or attempting to insert nil into a set, the debugger shows the stack from main() to __pthread_kill, without any of the frames that were present when the actual crashing code ran. There is a frame (9th from main) called objc_exception_rethrow. This leads me to believe that Cocoa Touch is trying to do something or other to recover all exceptions and die gracefully or something. However, it is very irritating when debugging to not have the ability to actually use Xcode4's debugging tools to investigate the calling stack frames, or even see where in my code I crashed.
Is there some way to make the objc_exception_rethrow behavior not happen, and just crash as soon as an exception is raised? Perhaps there's a debug setting that makes it crash earlier (at the right time)? (I haven't messed with any of the build settings in this project yet.)
I don't know any Xcode setting that could disable re-throwing exceptions. To my knowledge they are re-thrown by the runtime. You could try running the app without the debugger attached and let it crash. The crash report should contain a section "Last Exception Backtrace" which will give you exactly what you need in this case.
I found the answer: set a breakpoint on Obj-C Exceptions. It will go to the debugger when objc_exception_throw is hit, which is good. Unfortunately, this happens before the exception is printed, but we can make that happen anyway (most of the time) by setting the breakpoint's action to be (Debugger Action) po *(id *)($ebp + 8).