捕获异常

出现异常,程序继续执行。

- (void)viewDidLoad

{
    [super viewDidLoad];
NSArray *array = [NSArray arrayWithObjects:@"1",@"2",@"3",nil];
    @try {
        NSString * hello = [array objectAtIndex:5];
    }
    @catch (NSException *exception) {
        NSLog(@"exception name : %@",[exception name]);
        NSLog(@"exception reason : %@",[exception reason]);
        NSLog(@"exception stack : %@",[exception callStackSymbols]);
        NSLog(@"exception stack address : %@",[exception callStackReturnAddresses]);
    }
    NSLog(@"helo world");

}

2013-04-02 14:40:45.714 exceptionTest[8414:c07] exception name : NSRangeException
2013-04-02 14:40:45.716 exceptionTest[8414:c07] exception reason : *** -[__NSArrayI objectAtIndex:]: index 5 beyond bounds [0 .. 2]
2013-04-02 14:40:45.718 exceptionTest[8414:c07] exception stack : (
0   CoreFoundation                      0x01c9102e __exceptionPreprocess + 206
1   libobjc.A.dylib                     0x010cee7e objc_exception_throw + 44
2   CoreFoundation                      0x01c46b44 -[__NSArrayI objectAtIndex:] + 196
3   exceptionTest                       0x00002ead -[ViewController viewDidLoad] + 157
4   UIKit                               0x000f41c7 -[UIViewController loadViewIfRequired] + 536
5   UIKit                               0x000f4232 -[UIViewController view] + 33
6   UIKit                               0x000433d5 -[UIWindow addRootViewControllerViewIfPossible] + 66
7   UIKit                               0x0004376f -[UIWindow _setHidden:forced:] + 368
8   UIKit                               0x00043905 -[UIWindow _orderFrontWithoutMakingKey] + 49
9   UIKit                               0x0004c917 -[UIWindow makeKeyAndVisible] + 65
10  exceptionTest                       0x00002c5b -[AppDelegate application:didFinishLaunchingWithOptions:] + 571
11  UIKit                               0x00010157 -[UIApplication _handleDelegateCallbacksWithOptions:isSuspended:restoreState:] + 266
12  UIKit                               0x00010747 -[UIApplication _callInitializationDelegatesForURL:payload:suspended:] + 1248
13  UIKit                               0x0001194b -[UIApplication _runWithURL:payload:launchOrientation:statusBarStyle:statusBarHidden:] + 805
14  UIKit                               0x00022cb5 -[UIApplication handleEvent:withNewEvent:] + 1022
15  UIKit                               0x00023beb -[UIApplication sendEvent:] + 85
16  UIKit                               0x00015698 _UIApplicationHandleEvent + 9874
17  GraphicsServices                    0x01becdf9 _PurpleEventCallback + 339
18  GraphicsServices                    0x01becad0 PurpleEventCallback + 46
19  CoreFoundation                      0x01c06bf5 __CFRUNLOOP_IS_CALLING_OUT_TO_A_SOURCE1_PERFORM_FUNCTION__ + 53
20  CoreFoundation                      0x01c06962 __CFRunLoopDoSource1 + 146
21  CoreFoundation                      0x01c37bb6 __CFRunLoopRun + 2118
22  CoreFoundation                      0x01c36f44 CFRunLoopRunSpecific + 276
23  CoreFoundation                      0x01c36e1b CFRunLoopRunInMode + 123
24  UIKit                               0x0001117a -[UIApplication _run] + 774
25  UIKit                               0x00012ffc UIApplicationMain + 1211
26  exceptionTest                       0x00002962 main + 130
27  exceptionTest                       0x00002895 start + 53
28  ???                                 0x00000001 0x0 + 1
)
2013-04-02 14:40:45.719 exceptionTest[8414:c07] exception stack address : (0x1c91012 0x10cee7e 0x1c46b44 0x2ead 0xf41c7 0xf4232 0x433d5 0x4376f 0x43905 0x4c917 0x2c5b 0x10157 0x10747 0x1194b 0x22cb5 0x23beb 0x15698 0x1becdf9 0x1becad0 0x1c06bf5 0x1c06962 0x1c37bb6 0x1c36f44 0x1c36e1b 0x1117a 0x12ffc 0x2962 0x2895 0x1)
2013-04-02 14:40:45.720 exceptionTest[8414:c07] helo world

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值