当我使用@try @catch时,出现错误:预期标识符或'('在'try'Objective-c之前
@implementation BannerView
@synthesize timer;
@synthesize _responceInfo;
@synthesize recivedData;
@try {
NSString* const _mainUrl =
@"http://www.admobilapp.com/view.php?place_id=15&country_id=112&sex=3&rand=0.7858213884755969&gsmOperator=";
}
@catch (NSException * e) {
NSLog(@"Exception: %@", e);
}
@finally {
NSLog(@"finally");
}
NSString*const _ImagePath= @"\"image\":";
NSString*const _ImageClickUrl= @"\"link\":";
NSString*const _imagerotation = @"\"rotation\":";
如何解决?
错误:固定的标识符或'('在'try'Objective-c之前,已修复,但是现在如果我运行应用程序,我会遇到另一个错误,
应用程序崩溃了。
2012-02-27 00:28:02.794 Clicky [8409:9203]终于
2012-02-27 00:28:02.818 Clicky [8409:9203] *由于未捕获的异常'NSRangeException'而终止应用程序,原因:'-[NSCFString substringFromIndex:]:范围或索引超出范围'
**第一次调用时调用堆栈:
(
0 CoreFoundation 0x00db1be9异常预处理+ 185
1 libobjc.A.dylib 0x00f065c2 objc_exception_throw + 47
2 CoreFoundation 0x00d6a628 + [NSException提高:格式:参数:] + 136
3 CoreFoundation 0x00d6a59a + [NSException提高:格式:] + 58
4基础0x000250de-[NSString substringFromIndex:] + 133
5 Clicky 0x00003232-[BannerView ExtractStringKeyValue:] + 123
6 Clicky 0x000031b1-[BannerView ExtractImageUrl] + 48
7 Clicky 0x00003739-[BannerView刷新] + 59
8 Clicky 0x00003805-[BannerView initWithFrame:] + 157
9 UIKit 0x0049fce5 + [UIButton buttonWithType:] + 1373
10 Clicky 0x00002e6a-[示例viewDidLoad] + 51
11 UIKit 0x0036865e-[UIViewController视图] + 179
12 UIKit 0x0037b230-[UITabBarController transitionFromViewController:toViewController:transition:shouldSetSelected:] + 120
13 UIKit 0x00379d86-[UITabBarController transitionFromViewController:toViewController:] + 64
14 UIKit 0x0037bb7e-[UITabBarController _setSelectedViewController:] + 263
15 UIKit 0x0037b9ed-[UITabBarController _tabBarItemClicked:] + 352
16 UIKit 0x002baa6e-[UIApplication sendAction:to:from:forEvent:] + 119
17 UIKit 0x004b81f2-[UITabBar _sendAction:withEvent:] + 422
18 UIKit 0x002baa6e-[UIApplication sendAction:to:from:forEvent:] + 119
19 UIKit 0x003491b5-[UIControl sendAction:to:forEvent:] + 67
20 UIKit 0x0034b647-[UIControl(内部)_sendActionsForEvents:withEvent:] + 527
21 UIKit 0x0034916c-[UIControl sendActionsForControlEvents:] + 49
22 UIKit 0x002baa6e-[UIApplication sendAction:to:from:forEvent:] + 119
23 UIKit 0x003491b5-[UIControl sendAction:to:forEvent:] + 67
24 UIKit 0x0034b647-[UIControl(内部)_sendActionsForEvents:withEvent:] + 527
25 UIKit 0x0034a1f4-[UIControl touchesEnded:withEvent:] + 458
26 UIKit 0x002df0d1-[UIWindow _sendTouchesForEvent:] + 567
27 UIKit 0x002c037a-[UIApplication sendEvent:] + 447
28 UIKit 0x002c5732 _UIApplicationHandleEvent + 7576
29 GraphicsServices 0x016e7a36 PurpleEventCallback + 1550
30 CoreFoundation 0x00d93064 __CFRUNLOOP_IS_CALLING_OUT_TO_A_SOURCE1_PERFORM_FUNCTION + 52
31 CoreFoundation 0x00cf36f7 __CFRunLoopDoSource1 + 215
32 CoreFoundation 0x00cf0983 __CFRunLoopRun + 979
33 CoreFoundation 0x00cf0240 CFRunLoopRunSpecific + 208
34 CoreFoundation 0x00cf0161 CFRunLoopRunInMode + 97
35图形服务0x016e6268 GSEventRunModal + 217
36个GraphicsServices 0x016e632d GSEventRun + 115
37 UIKit 0x002c942e UIApplicationMain + 1160
38 Clicky 0x00002840主+ 102
39 Clicky 0x000027d1开始+ 53
)
终止称为引发异常
@try @catch不起作用。 :(。
最佳答案
您不能在方法主体之外使用@try/@catch/@finally
。无论如何,分配静态字符串都不会失败。
关于objective-c - 错误:期望的标识符或'('在'try'Objective-c之前,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9457547/