【问题标题】:error: expected identifier or '(' before 'try' objective-c错误:预期标识符或“尝试”之前的“(”目标-c
【发布时间】:2012-03-16 11:38:18
【问题描述】:

当我使用@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\":";

如何解决?

error: '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 raise:format:arguments:] + 136 3 CoreFoundation 0x00d6a59a +[NSException raise:format:] + 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 发送事件:] + 447 28 UIKit 0x002c5732 _UIApplicationHandleEvent + 7576 29 图形服务 0x016e7a36 PurpleEventCallback + 1550 30 核心基础 0x00d93064 __CFRUNLOOP_IS_CALLING_OUT_TO_A_SOURCE1_PERFORM_FUNCTION + 52 31 核心基础 0x00cf36f7 __CFRunLoopDoSource1 + 215 32 核心基础 0x00cf0983 __CFRunLoopRun + 979 33 核心基础 0x00cf0240 CFRunLoopRunSpecific + 208 34 核心基础 0x00cf0161 CFRunLoopRunInMode + 97 35 图形服务 0x016e6268 GSEventRunModal + 217 36 图形服务 0x016e632d GSEventRun + 115 37 UIKit 0x002c942e UIApplicationMain + 1160 38 Clicky 0x00002840 主 + 102 39 Clicky 0x000027d1 开始 + 53 ) 终止称为抛出异常

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

【问题讨论】:

  • 在此之前发布代码。错误不在这里。
  • 这段代码在方法中吗?或者它只是在实现中独自闲逛?
  • @Peter M 我也是这么想的 :)

标签: objective-c ios try-catch


【解决方案1】:

你不能在方法体之外使用@try/@catch/@finally。分配静态字符串无论如何都不会失败。

【讨论】:

    【解决方案2】:

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

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2014-01-31
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多