2012-02-26 94 views
0

當我使用@try @catch,我得到錯誤:預期的標識符或 '(' 前 '嘗試' 的Objective-C錯誤:預期標識符或 '(' '嘗試' 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\":"; 

如何修復

錯誤:?預期標識符或「(」前「嘗試」 Objective-C的,固定的,但現在如果我運行應用程序,我有另一個錯誤, 和APP是崩潰

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 exceptionPreprocess + 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 - [UIViewControll ER視圖] + 179 12的UIKit 0x0037b230 - [的UITabBarController transitionFromViewController:toViewController:過渡: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:爲:從: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:爲:從:forEvent:] + 119 23的UIKit 0x003491b5 - [UIControl sendAction:至: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 PurpleEventCa llback + 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 ) 終止調用拋出異常

@try @catch不起作用。 :(。

+2

後的代碼在此之前,誤差不在這裏 – sch 2012-02-26 21:58:35

+2

這個代碼是在一個方法中嗎?或者它只是在執行時自己把所有的東西都掛起來了? – 2012-02-26 22:04:08

+0

@Peter MI認爲同樣的東西:) – Max 2012-02-26 22:07:37

回答

3

不能使用@try/@catch/@finally方法體外。分配一個靜態字符串無論如何不能失敗。

1

不能的方法之外編寫代碼。

相關問題