简体   繁体   中英

error: expected identifier or '(' before 'try' objective-c

When i use @try @catch, i get error: expected identifier or '(' before '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\":";

How to fix it?

error: expected identifier or '(' before 'try' objective-c, fixed, but now if i run application i have another error, And app is crash.

2012-02-27 00:28:02.794 Clicky[8409:9203] finally 2012-02-27 00:28:02.818 Clicky[8409:9203] * Terminating app due to uncaught exception 'NSRangeException', reason: ' -[NSCFString substringFromIndex:]: Range or index out of bounds' * * Call stack at first throw: ( 0 CoreFoundation 0x00db1be9 exceptionPreprocess + 185 1 libobjc.A.dylib 0x00f065c2 objc_exception_throw + 47 2 CoreFoundation 0x00d6a628 +[NSException raise:format:arguments:] + 136 3 CoreFoundation 0x00d6a59a +[NSException raise:format:] + 58 4 Foundation 0x000250de -[NSString substringFromIndex:] + 133 5 Clicky 0x00003232 -[BannerView ExtractStringKeyValue:] + 123 6 Clicky 0x000031b1 -[BannerView ExtractImageUrl] + 48 7 Clicky 0x00003739 -[BannerView Refresh] + 59 8 Clicky 0x00003805 -[BannerView initWithFrame:] + 157 9 UIKit 0x0049fce5 +[UIButton buttonWithType:] + 1373 10 Clicky 0x00002e6a -[Examples viewDidLoad] + 51 11 UIKit 0x0036865e -[UIViewController view] + 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(Internal) _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(Internal) _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 + 75 76 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 GraphicsServices 0x016e6268 GSEventRunModal + 217 36 GraphicsServices 0x016e632d GSEventRun + 115 37 UIKit 0x002c942e UIApplicationMain + 1160 38 Clicky 0x00002840 main + 102 39 Clicky 0x000027d1 start + 53 ) terminate called throwing an exception

@try @catch doesn't work. :(.

You cannot use @try/@catch/@finally outside a method body. Assigning a static string cannot fail anyway.

您不能在方法之外编写代码。

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM