I am using Adobe Air3.4 to develop an app on iOS. However, I met a crash only on release version and this crash doesn't happen on debug version. But I cannot get any crash info such as callstack from iOS. Do you have any method to deal with this kind of problem?
You can wrap the offending code in a try/catch statement. Inside the catch code block, you get an Error object that you can use to get the stack trace:
try
{
// some code that throws an exception
}
catch (e:Error)
{
trace(e.getStackTrace())
}
If you don't know which code is causing the error, and thus where to add the try/catch statement, you might have some luck with the UncaughtErrorEvent -- refer to the examples found at the bottom of the documentation for UncaughtErrorEvent that I linked to.
In fact, if you just want a stack trace in general, create a new Error object and use its getStackTrace() method anywhere in your code.
In addition to checking for errors as above, you should check the crash logs on your device to see if that provides any additional details.
Related
Is there a way to parse iOS's log to a String at run time when it occurred? I need to parse a certain error log from UIKit and assert it at once when it appeared for debugging.
What we want to do is to parse the console for this error: This application is modifying the autolayout engine from a background thread after the engine was accessed from the main thread. This can lead to engine corruption and weird crashes. We've found and fixed the line that causes this error, but we need to prevent this for happening again. FYI, the culprit is a line that changes a constant of an Autolayout in a background thread. And unfortunately it is not recognized by the compiler as an error like when we do the same thing with UIButton or anything that is derived from UIView (which will give an error at compile time when we try putting it in a background thread).
After much googling for the answer, I've finally found the answer. I found this article:
So here's what I did:
Eavesdropping on stderr stream
Duplicate it into another string
Parse the string for "weird crashes"
If found, it will crash immediately (instead of still running the app and waiting for the app to crash at indefinite time)
Added a DEBUG guard so that this functionality doesn't get carried over to production
I've been debugging for several hours, read some articles but still can't find what's wrong.
I've switched on ARC, but I found that my BIDGameScence will be deallocated strangely, and I don't know why.(I've checked that all pointer to BIDGameScene is strong.) I went through call stack when selector dealloc was called, but there's no selector written by myself in the stack(I think the last stack frame is a function used to send a message).
I also tried Zombies, but I just got Message send to deallocated object. An article says that I should use malloc_info, but I'm using lldb and got malloc_info is not a valid command.(I found that there is no gdb in my XCode.)
What's more, I added a NSLog statement in applicationDidReceiveMemoryWarning, but I did't find it in the logging.
Finally I tried to use Product->Analyze, but got nothing.
So, how to debug this error?
I'm using XCode 4.
Is there anyway in ios to handle all the exceptions that occurred in entire application in a single try catch block.
If yes where should I write this block.
You might want to have a look into the concept of handling exceptions globally in iOS. I might not be able to give the most correct answer but these links can spread some more light on what you might just want.
iOS Global Exception Handling
Global Exception Handler in iOS
Hope this helps.
Assuming the question is about Objective-C there is no need to handle exceptions because they are not to be used for program control. Exceptions are only to be used to catch non-recoverable programming errors so if you get one the code needs to be fixed.
In general exceptions across stack frames are not handled in a manner that is recoverable.
The best thing to do is add an exception breakpoint in Xcode so you can better examine exceptions:
From the Mian Menu Debug:Breakpoints:Create Exception Breakpoint. Run the app to get the breakpoint. When you hit the exception breakpoint click debug continue a couple of times and you will get a backtrace and more error info. Add that and an exact copy of Xcode/Debugger messages to the question.
It is also a good idea to change this breakpoint to "Objective-C only."
You can use NSSetUncaughtExceptionHandler to set the handler.
Swift:
NSSetUncaughtExceptionHandler { (exception) in
while true {
sleep(UInt32(0.5))
}
}
Objective-C:
void handleException(NSException* exception) {
while true {
sleep(0.5);
}
}
NSSetUncaughtExceptionHandler(handleException);
When the handler is returned, the app crashes and Xcode shows the error. So you can run a loop until you want to quit the app. I do not recommend to keep the app running normally, but you can show for example an alert saying an error occurred and when the user taps a button, the app crashes. Use a flag for the loop.
I am getting an EXC_BAD_ACCESS. I know what this usually means: Trying to access an object that doesn't exist (anymore) is the most likely cause.
So, where do I find that?
I have read numerous posts on the internet, and they all say:
"Enable NSZombie" in the scheme.
Now when I run the debugger, for what should I look? I can not see any difference...
Note: This is not about a perticular error in my code, but generally how to use the debugger with NSZombie enabled
What I would do it will be to locate a breakpoint just one line above the green arrow showing the EXC_BAD_ACCESS error. Then run again your code and reproduce the steps to generate the crash.
When you get to your breakpoint you can check that your objects are valid objects using right click and print description in the left side of your console within Xcode or typing the command 'po' within the console section in XCode. That's how I usually detect the errors.
Something useful is to trace the stack once the debugger stopped. It show in the left panel the threads and chain of invocations of the methods before the break point.
Hope this helps and hope my description of the alternative in how to track the error helps.
Write code in #synchronized(){} block.
Try this:
#synchronized (self){ //Your Code }
All,
I have a chunk of code that runs over a lot of records and in about half of the cases fails (this is ok, some records simply don't have the required data) I put this code in a #try #catch block to make it run smoothly, we try to do our thing, if we fail, we have some default action.
When it fails in the #try block often it is a unrecognized selector error, since it is in the #try block I catch this error, but it still gets logged everytime, even when I don't log from my #catch block. This is very annoying because it clogs up my logging. If I want errors from a #try/#catch logged, I will take care of that in the #catch right?
How can I stop XCode from logging errors in the #try block that are subsequently resolved in the #catch block?
I am using XCode 4.2
Thanks
In Objective-C using exceptions for any normal situation that can appear in a program is a no go. Exceptions are used only for discovering and catching programming errors and terminating gracefully. The problem is that all of the standard libraries (Cocoa, CoreFoundation, C standard library, ...) just are not build to handle exceptions and would fail to clean up resources if exceptions went through them.
Theoretically you could use exceptions if you made sure that you do your memory and other cleanup correctly and do not throw through foreign code. If you use ARC, there's a compiler switch -fobjc-arc-exceptions that would help you to get memory management (in your code) right.
Common practice is not to use exceptions at all (other than bugs, for example using NSAssert).
Exceptions themselves do not log any message to the console. Neither does Xcode (by default) log any exception throwing.
It's the error catching code that writes the messages before throwing exceptions. NSObject's doesNotRecognizeSelector: prints a message when unrecognized selectors are being sent. You cannot turn this off.
So you want to see certain log message but not others. How about redirecting the debugger output into a file. On that file use grep or a text editor with nice filtering to scan through message you want to see. Copy & paste from the gdb console into an edtor would do the same trick.