I'm trying to run my tests scripts on different device(iPhone, iPad, Air), but all the same. When i push Play button ,app started and crashed. And my scripts can not be executed.(Simply stopped). Please tell me why!?I use UI automation tool.
Thanks!
in main.m in main function use this code,
#try {
#autoreleasepool {
return UIApplicationMain(argc, argv, nil, NSStringFromClass([RRAppDelegate class]));
}
}
#catch (NSException *exception) {
NSLog( #"There is some error === %#",[NSString stringWithFormat:#"%#",exception]);
}
It will show u the err reason. I haven't 50 reputation, so i am unable to comment.
Related
I am developing an app in which I have to track crashes. There is a restriction that I can't use any third party source like Twitter's Fabric framework to handle crash logging.
Currently I am only able to get the reason for crash. I am not able to get the exact point of crash.
What I am doing:
In my app delegate's didFinishLaunchingWithOptions method I had made my own exception handler:
NSSetUncaughtExceptionHandler(&uncaughtExceptionHandler);
uncaughtExceptionHandler ----
void uncaughtExceptionHandler(NSException *exception) {
NSLog(#"CRASH: %#", exception);
NSLog(#"callStackSymbols: %#", [exception callStackSymbols]);
NSLog(#"callStackReturnAddresses: %#", [exception callStackReturnAddresses]);
NSLog(#"reason: %#", [exception reason]);
NSLog(#"name: %#", [exception name]);
NSLog(#"%s %d %s %s", __FILE__, __LINE__, __PRETTY_FUNCTION__, __FUNCTION__);
// Internal error reporting
}
I crashed my app in viewDidLoad method using this:
NSArray *myary;
myary = [NSArray arrayWithObjects:#"sad", nil];
NSString *str = [myary objectAtIndex:22];
Here is my Stack Trace.
Is their any way to achieve what I want?
I tried following these solutions from SO but they don't give me any lead:
Solution 1
Solution 2
I wanna check the UITextField is String or number by using try catch.
But it seems doesn't work. Here is my code:
- (IBAction)add {
#try {
double firstNumber = self.firstNumber.text.doubleValue;
double secondNumber = self.secondNumber.text.doubleValue;
Calculator *calcu = [[Calculator alloc] initWithFirstNumber:firstNumber andSecondNumber:secondNumber andOperation:#"+"];
self.result.text = calcu.calculateTwoNumber;
}
#catch (NSException *exception) {
self.result.text = #"Please enter right number!";
}
#finally {
}
}
Follow code:
#try {
self.labelName.text=[arrName ObjectAtIndex:indexPath.row];
}
#catch (NSException *exception) {
NSLog(#"Something missing...");
}
#finally {
}
What Claus Bönnhoff wrote in the comments cannot be overemphasized: Objective-C is not Java or C#.
The accepted way to use exceptions in Obj-C is for unrecoverable errors, not simple flow control.
The answer to your question, then, is that exceptions should be used very rarely. In several years of iOS development, I haven't used them a single time. I also have not come accross them in anyone else's code.
I have, however, encountered exceptions thrown by the Obj-C runtime, which I suppose gives some indication of what their role might be.
I am experiencing frequent crashing that I believe is related to this method of checking the number of MIDINetwork Sessions.
- (NSString*) describeConnections {
NSMutableArray* connections = [NSMutableArray arrayWithCapacity:1000];
for (MIDINetworkConnection* connection in [[MIDINetworkSession defaultSession] connections]) {
[connections addObject:[[connection host] name]];
}
if ([connections count] > 0) {
return [connections componentsJoinedByString:#", "];
}
else
return #"(Not connected)";
}
When the app crashes it stops on the line
for (MIDINetworkConnection* connection in [[MIDINetworkSession defaultSession] connections])
The error I am getting is
Thread 1: EXC_BAD_ACCESS(code=EXC_1386_GPFLT)
In the debugger it shows
_impl _MIDINetworkConnectionImpl * NULL
I have tried to prevent the crashing by checking if MIDINetworkSession is NULL before looping through the connections but that hasn't worked. Occasionally when xcode crashes it will stop at
int main(int argc, char *argv[])
{
#autoreleasepool {
int retVal = UIApplicationMain(argc, argv, nil, nil);
return retVal;
}
}
Can anyone offer a guess as to what's happening?
It seems that connections contain NULL, in some case the system dealloc the connections.But in the set, it cannot use the NULL to be elements, so you should check the connections or use the try catch to get the exception.
I want to integrate in my iPad application a way to monitor the user activity and especially the exceptions that occurred and triggered the application to stop, something like the bug report of Apple but for the mobile clients.
I tried to encapsulate the main action (main.m) between #try and #catch blocks, but the exception is not thrown until there, and I just can't add such blocks everywhere in my code. Neither the delegate method applicationWillTerminate is not called, the application is just brutally stopped without any notification.
Any ideas on this ?
It works for me in main.m
int main(int argc, char *argv[]) {
#autoreleasepool {
int retVal = 0;
#try {
retVal = UIApplicationMain(argc, argv, nil, NSStringFromClass([AppDelegate class]));
}
#catch (NSException *exception) {
NSLog(#"Exception: %#", exception);
[exception raise];
}
return retVal;
}
}
P.S.
Another tricky way : EXC_BAD_ACCESS automatic handling
And example of NSUncaughtExceptionHandler
If I put a try catch and finally inside an async GCD call the finally generally seems to not get executed and I am not sure about the catch either, seems to execute some of the time.
dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_HIGH, 0), ^{
#try {
[self methodThatAlwaysThrowsAnException];
}#catch (NSException *exc) {
NSLog(#"Caught the Exception %#",exc);
}#finally{
NSLog(#"Should always execute");
}
});
Does anyone know why this is?
Consequently I put the finally call outside of dispatch_async but I would prefer to know that my try was fully executed.
Try to avoid #try/#catch for control-flow operations.
Also, your code sample works fine for me. The #finally block is always executed, as is the #catch block if there was an exception thrown.