iOS exception handling problem - iphone

I have problem in following code.
int i = 10;
NSString *str;
#try {
//Error
str = [[NSString alloc] initWithFormat:#"%#",i];
//Warning
NSLog(#"%i",str);
}
#catch (id exception) {
NSLog(#"Hello !!!");
}
Please help me out how to handle exception in i/o operation.
Thanks.
Edited by Justin
there's no suitable place for me to provide this program to you, so i put it here.
try using the following program to reformulate your question:
static void bad_program() {
#try {
id array = [NSArray array];
NSLog(#"will throw...");
[array stringByAbbreviatingWithTildeInPath];
}
#catch (id exception) {
NSLog(#"\n*** Caught Exception:\n***** Exception Detail: %#\nResolution: Exception swallowed\n", exception);
}
}
# Justin, Result of above code
It does not fire exception. It is crashed showing following error.
Sorry Justin, please see if you could help me more. Thanks.
2011-08-25 15:06:48.444 TestError[5120:b303] will throw...
2011-08-25 15:06:48.446 TestError[5120:b303] -[__NSArrayI stringByAbbreviatingWithTildeInPath]: unrecognized selector sent to instance 0x4b38e10
2011-08-25 15:06:48.465 TestError[5120:b303] *** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[__NSArrayI stringByAbbreviatingWithTildeInPath]: unrecognized selector sent to instance 0x4b38e10'
*** Call stack at first throw:
(
0 CoreFoundation 0x00dc05a9 __exceptionPreprocess + 185
1 libobjc.A.dylib 0x00f14313 objc_exception_throw + 44
2 CoreFoundation 0x00dc20bb -[NSObject(NSObject) doesNotRecognizeSelector:] + 187
3 CoreFoundation 0x00d31966 ___forwarding___ + 966
4 CoreFoundation 0x00d31522 _CF_forwarding_prep_0 + 50
5 TestError 0x00002454 -[TestErrorViewController viewDidLoad] + 164
6 UIKit 0x000c2089 -[UIViewController view] + 179
7 UIKit 0x00035d42 -[UIWindow addRootViewControllerViewIfPossible] + 51
8 TestError 0x00002087 -[TestErrorAppDelegate application:didFinishLaunchingWithOptions:] + 135
9 UIKit 0x00012c89 -[UIApplication _callInitializationDelegatesForURL:payload:suspended:] + 1163
10 UIKit 0x00014d88 -[UIApplication _runWithURL:payload:launchOrientation:statusBarStyle:statusBarHidden:] + 439
11 UIKit 0x0001f617 -[UIApplication handleEvent:withNewEvent:] + 1533
12 UIKit 0x00017abf -[UIApplication sendEvent:] + 71
13 UIKit 0x0001cf2e _UIApplicationHandleEvent + 7576
14 GraphicsServices 0x00ff9992 PurpleEventCallback + 1550
15 CoreFoundation 0x00da1944 __CFRUNLOOP_IS_CALLING_OUT_TO_A_SOURCE1_PERFORM_FUNCTION__ + 52
16 CoreFoundation 0x00d01cf7 __CFRunLoopDoSource1 + 215
17 CoreFoundation 0x00cfef83 __CFRunLoopRun + 979
18 CoreFoundation 0x00cfe840 CFRunLoopRunSpecific + 208
19 CoreFoundation 0x00cfe761 CFRunLoopRunInMode + 97
20 UIKit 0x000147d2 -[UIApplication _run] + 623
21 UIKit 0x00020c93 UIApplicationMain + 1160
22 TestError 0x00001fc9 main + 121
23 TestError 0x00001f45 start + 53
24 ??? 0x00000001 0x0 + 1
)
terminate called throwing an exceptionsharedlibrary apply-load-rules all

I got answer of this question.
Some exception cannnot catch and some exception will only work for device not on the simulator.

Related

NSUnknownKeyException facing error

I am newbie for iOS Please help ,When I run the code for the first time, it runs successfully in emulator along with the correct output. Now for the same code it show the following error:
2015-10-09 11:25:30.569 ViewController[1417:44846] * Terminating app
due to uncaught exception 'NSUnknownKeyException', reason:
'[ setValue:forUndefinedKey:]: this
class is not key value coding-compliant for the key outlinebtn.'
* First throw call stack:
( 0 CoreFoundation 0x000000010c840f35
exceptionPreprocess + 165 1 libobjc.A.dylib 0x000000010c130bb7 objc_exception_throw + 45 2 CoreFoundation
0x000000010c840b79 -[NSException raise] + 9 3 Foundation
0x000000010bccd7b3 -[NSObject(NSKeyValueCoding) setValue:forKey:] +
259 4 CoreFoundation 0x000000010c78ae80
-[NSArray makeObjectsPerformSelector:] + 224 5 UIKit 0x000000010cef2c7d -[UINib instantiateWithOwner:options:] + 1506 6
UIKit 0x000000010cd51f98
-[UIViewController _loadViewFromNibNamed:bundle:] + 242 7 UIKit 0x000000010cd52588 -[UIViewController loadView] + 109 8 UIKit
0x000000010cd527f9 -[UIViewController loadViewIfRequired] + 75 9
UIKit 0x000000010cd52c8e
-[UIViewController view] + 27 10 UIKit 0x000000010cc71ca9 -[UIWindow addRootViewControllerViewIfPossible] +
58 11 UIKit 0x000000010cc72041
-[UIWindow _setHidden:forced:] + 247 12 UIKit 0x000000010cc7e72c -[UIWindow makeKeyAndVisible] + 42 13 UIKit
0x000000010cc29061 -[UIApplication
_callInitializationDelegatesForMainScene:transitionContext:] + 2628 14 UIKit 0x000000010cc2bd2c
-[UIApplication _runWithMainScene:transitionContext:completion:] + 1350 15 UIKit 0x000000010cc2abf2
-[UIApplication workspaceDidEndTransaction:] + 179 16 FrontBoardServices 0x000000010f3e92a3
__31-[FBSSerialQueue performAsync:]_block_invoke + 16 17 CoreFoundation 0x000000010c77653c
__CFRUNLOOP_IS_CALLING_OUT_TO_A_BLOCK + 12 18 CoreFoundation 0x000000010c76c285 __CFRunLoopDoBlocks + 341 19 CoreFoundation
0x000000010c76ba43 __CFRunLoopRun + 851 20 CoreFoundation
0x000000010c76b486 CFRunLoopRunSpecific + 470 21 UIKit
0x000000010cc2a669 -[UIApplication _run] + 413 22 UIKit
0x000000010cc2d420 UIApplicationMain + 1282 23 ViewController
0x000000010bc01e43 main + 115 24 libdyld.dylib
0x000000010edd0145 start + 1 ) libc++abi.dylib: terminating with
uncaught exception of type NSException (lldb)
#import <UIKit/UIKit.h>
#import "AppDelegate.h"
int main(int argc, char * argv[]) {
#autoreleasepool {
return UIApplicationMain(argc, argv, nil, NSStringFromClass([AppDelegate class]));
}
}
What to do ??/ please help me. I am new for iOS

SIGABRT Error on Button Click xcode

I am having a strange problem in xcode. i created a button in xib and connected to a function. I am printing the message inside the function. That's all, when i click the button i get the following error. I tried clean and deleted app from my simulator.
-(IBAction)languageSelection:(id)sender is my function name
-[NSCFString languageSelection:]: unrecognized selector sent to instance 0x713cd40
2012-05-03 15:14:35.055 Example[33420:207] *** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[NSCFString languageSelection:]: unrecognized selector sent to instance 0x713cd40'
*** Call stack at first throw:
(
0 CoreFoundation 0x02966919 __exceptionPreprocess + 185
1 libobjc.A.dylib 0x02ab45de objc_exception_throw + 47
2 CoreFoundation 0x0296842b -[NSObject(NSObject) doesNotRecognizeSelector:] + 187
3 CoreFoundation 0x028d8116 ___forwarding___ + 966
4 CoreFoundation 0x028d7cd2 _CF_forwarding_prep_0 + 50
5 UIKit 0x005ece14 -[UIApplication sendAction:to:from:forEvent:] + 119
6 UIKit 0x006766c8 -[UIControl sendAction:to:forEvent:] + 67
7 UIKit 0x00678b4a -[UIControl(Internal) _sendActionsForEvents:withEvent:] + 527
8 UIKit 0x006776f7 -[UIControl touchesEnded:withEvent:] + 458
9 UIKit 0x006102ff -[UIWindow _sendTouchesForEvent:] + 567
10 UIKit 0x005f21ec -[UIApplication sendEvent:] + 447
11 UIKit 0x005f6ac4 _UIApplicationHandleEvent + 7495
12 GraphicsServices 0x02dedafa PurpleEventCallback + 1578
13 CoreFoundation 0x02947dc4 __CFRUNLOOP_IS_CALLING_OUT_TO_A_SOURCE1_PERFORM_FUNCTION__ + 52
14 CoreFoundation 0x028a8737 __CFRunLoopDoSource1 + 215
15 CoreFoundation 0x028a59c3 __CFRunLoopRun + 979
16 CoreFoundation 0x028a5280 CFRunLoopRunSpecific + 208
17 CoreFoundation 0x028a51a1 CFRunLoopRunInMode + 97
18 GraphicsServices 0x02dec2c8 GSEventRunModal + 217
19 GraphicsServices 0x02dec38d GSEventRun + 115
20 UIKit 0x005fab58 UIApplicationMain + 1160
21 Example 0x000023c9 main + 121
22 Example 0x00002345 start + 53
)
terminate called after throwing an instance of 'NSException'
this is perhaps you are trying to call a method languageSelection with object that is infact string, but you have passed into another object which has languageSelection method.
this is because you think the object is what you want but the pointer passed the allocated memory to string and hence it will work as string. when you try to call method it crashes because it didn't find the method in string. check your object type just before u use it anywhere

How to debug 'unrecognized selector sent to instance' error in Xcode?

2011-04-26 01:36:17.914 Protoype_Test1[15119:207] -[Protoype_Test1ViewController saveImage]: unrecognized selector sent to instance 0x5f60e60
2011-04-26 01:36:17.933 Protoype_Test1[15119:207] *** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[Protoype_Test1ViewController saveImage]: unrecognized selector sent to instance 0x5f60e60'
*** Call stack at first throw:
(
0 CoreFoundation 0x0126cbe9 __exceptionPreprocess + 185
1 libobjc.A.dylib 0x010615c2 objc_exception_throw + 47
2 CoreFoundation 0x0126e6fb -[NSObject(NSObject) doesNotRecognizeSelector:] + 187
3 CoreFoundation 0x011de366 ___forwarding___ + 966
4 CoreFoundation 0x011ddf22 _CF_forwarding_prep_0 + 50
5 UIKit 0x00366a6e -[UIApplication sendAction:to:from:forEvent:] + 119
6 UIKit 0x003f51b5 -[UIControl sendAction:to:forEvent:] + 67
7 UIKit 0x003f7647 -[UIControl(Internal) _sendActionsForEvents:withEvent:] + 527
8 UIKit 0x003f61f4 -[UIControl touchesEnded:withEvent:] + 458
9 UIKit 0x0038b0d1 -[UIWindow _sendTouchesForEvent:] + 567
10 UIKit 0x0036c37a -[UIApplication sendEvent:] + 447
11 UIKit 0x00371732 _UIApplicationHandleEvent + 7576
12 GraphicsServices 0x01a83a36 PurpleEventCallback + 1550
13 CoreFoundation 0x0124e064 __CFRUNLOOP_IS_CALLING_OUT_TO_A_SOURCE1_PERFORM_FUNCTION__ + 52
14 CoreFoundation 0x011ae6f7 __CFRunLoopDoSource1 + 215
15 CoreFoundation 0x011ab983 __CFRunLoopRun + 979
16 CoreFoundation 0x011ab240 CFRunLoopRunSpecific + 208
17 CoreFoundation 0x011ab161 CFRunLoopRunInMode + 97
18 GraphicsServices 0x01a82268 GSEventRunModal + 217
19 GraphicsServices 0x01a8232d GSEventRun + 115
20 UIKit 0x0037542e UIApplicationMain + 1160
21 Protoype_Test1 0x00001c34 main + 102
22 Protoype_Test1 0x00001bc5 start + 53
)
terminate called after throwing an instance of 'NSException'
see if the IBAction of the buttons are connected properly. I guess they are not properly connected
It would be much helpful if you post your source code rather than error out come.
Anyway i think you are trying to call an instance method through class reference.
The problem is here:
[Protoype_Test1ViewController saveImage]
It should be:
[protoype_Test1ViewController saveImage]
This is a common mistake when relay much on auto complete.

Error in dismissing a modal view controller

I have encountered application termination while dismissing a modal view controller.
-[NSCFString window]: unrecognized selector sent to instance 0x6337dc0
2011-06-03 13:26:37.980 Tuscany[19657:207] *** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[NSCFString window]: unrecognized selector sent to instance 0x6337dc0'
*** Call stack at first throw:
(
0 CoreFoundation 0x016ffbe9 __exceptionPreprocess + 185
1 libobjc.A.dylib 0x018545c2 objc_exception_throw + 47
2 CoreFoundation 0x017016fb -[NSObject(NSObject) doesNotRecognizeSelector:] + 187
3 CoreFoundation 0x01671366 ___forwarding___ + 966
4 CoreFoundation 0x01670f22 _CF_forwarding_prep_0 + 50
5 UIKit 0x003f4024 -[UIViewController viewControllerForRotation] + 81
6 UIKit 0x003ee8ab -[UIViewController shouldWindowUseOnePartInterfaceRotationAnimation:] + 34
7 UIKit 0x00368dd5 -[UIWindow _clientsForRotation] + 350
8 UIKit 0x0036b87b -[UIWindow _setRotatableClient:toOrientation:updateStatusBar:duration:force:] + 141
9 UIKit 0x005eb948 -[UIWindowController transition:fromViewController:toViewController:target:didEndSelector:] + 1053
10 UIKit 0x003f7682 -[UIViewController _dismissModalViewControllerWithTransition:from:] + 2075
11 UIKit 0x003f4324 -[UIViewController dismissModalViewControllerWithTransition:] + 579
12 Foundation 0x000c37f6 __NSFireDelayedPerform + 441
13 CoreFoundation 0x016e0fe3 __CFRUNLOOP_IS_CALLING_OUT_TO_A_TIMER_CALLBACK_FUNCTION__ + 19
14 CoreFoundation 0x016e2594 __CFRunLoopDoTimer + 1220
15 CoreFoundation 0x0163ecc9 __CFRunLoopRun + 1817
16 CoreFoundation 0x0163e240 CFRunLoopRunSpecific + 208
17 CoreFoundation 0x0163e161 CFRunLoopRunInMode + 97
18 GraphicsServices 0x01d88268 GSEventRunModal + 217
19 GraphicsServices 0x01d8832d GSEventRun + 115
20 UIKit 0x0035342e UIApplicationMain + 1160
21 Tuscany 0x00002878 main + 102
22 Tuscany 0x00002809 start + 53
)
terminate called after throwing an instance of 'NSException'
Above is the crash log. Please help.
Thanks in advance.
From you log it seems that you are calling window on an NSCFString. NSCFString does not have a window selector, and the compiler would complain if you try and do so, so it is likely that you are sending that message to a deallocated object (imagine that a new object has been allocated where another one was previously), or you are messing with casts.
In case you suspect that you are sending the message to a deallocated object, enable NSZombies.
Without seeing the code, it is not possible to help you further, though.

iphone App crashes while Parsing

my app is crashed as it execute [NSXMLParser parse]; statement,and
i am getting following :
2011-03-01 09:36:31.735 MasterApp[228:207] -[NSCFString bytes]: unrecognized selector sent to instance 0x5f6b000
2011-03-01 09:36:31.738 MasterApp[228:207] * Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[NSCFString bytes]: unrecognized selector sent to instance 0x5f6b000'
* Call stack at first throw:
(
0 CoreFoundation 0x0252eb99 exceptionPreprocess + 185
1 libobjc.A.dylib 0x0267e40e objc_exception_throw + 47
2 CoreFoundation 0x025306ab -[NSObject(NSObject) doesNotRecognizeSelector:] + 187
3 CoreFoundation 0x024a02b6 __forwarding + 966
4 CoreFoundation 0x0249fe72 _CF_forwarding_prep_0 + 50
5 Foundation 0x00114afc -[NSXMLParser parse] + 147
6 MasterApp 0x0000c731 -[identifierList getUrl] + 994
7 MasterApp 0x0000c306 -[identifierList actionSheet:clickedButtonAtIndex:] + 56
8 UIKit 0x0077047d -[UIActionSheet(Private) _buttonClicked:] + 258
9 UIKit 0x002dc7f8 -[UIApplication sendAction:to:from:forEvent:] + 119
10 UIKit 0x00367de0 -[UIControl sendAction:to:forEvent:] + 67
11 UIKit 0x0036a262 -[UIControl(Internal) _sendActionsForEvents:withEvent:] + 527
12 UIKit 0x00368e0f -[UIControl touchesEnded:withEvent:] + 458
13 UIKit 0x003003d0 -[UIWindow _sendTouchesForEvent:] + 567
14 UIKit 0x002e1cb4 -[UIApplication sendEvent:] + 447
15 UIKit 0x002e69bf _UIApplicationHandleEvent + 7672
16 GraphicsServices 0x02d8a822 PurpleEventCallback + 1550
17 CoreFoundation 0x0250fff4 CFRUNLOOP_IS_CALLING_OUT_TO_A_SOURCE1_PERFORM_FUNCTION + 52
18 CoreFoundation 0x02470807 __CFRunLoopDoSource1 + 215
19 CoreFoundation 0x0246da93 __CFRunLoopRun + 979
20 CoreFoundation 0x0246d350 CFRunLoopRunSpecific + 208
21 CoreFoundation 0x0246d271 CFRunLoopRunInMode + 97
22 GraphicsServices 0x02d8900c GSEventRunModal + 217
23 GraphicsServices 0x02d890d1 GSEventRun + 115
24 UIKit 0x002eaaf2 UIApplicationMain + 1160
25 MasterApp 0x00001dbc main + 102
26 MasterApp 0x00001d4d start + 53
)
terminate called after throwing an instance of 'NSException'
Program received signal: “SIGABRT”.
thank you in advance
i just try to use "urlData" instead of webData in xmlParser = [[NSXMLParser alloc] initWithData:urlData]; and now it parse very well