如何修复LLDB:如果它不是出口错误,则以NSException类型的未捕获异常终止?

时间:2016-01-13 14:54:43

标签: ios xcode firebase lldb

我已经找到了这个问题的答案,似乎答案总是被遗忘了。但在我的情况下,没有那个。

每次调用某个Firebase方法时,我都会收到错误消息,但只有在某个' if-else'

之后才会收到消息错误

顺便说一下,完整的信息:

*** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '*** -[__NSPlaceholderDictionary initWithObjects:forKeys:count:]: attempt to insert nil object from objects[0]'
*** First throw call stack:
(
    0   CoreFoundation                      0x0000000102dffe65 __exceptionPreprocess + 165
    1   libobjc.A.dylib                     0x0000000102878deb objc_exception_throw + 48
    2   CoreFoundation                      0x0000000102d028ce -[__NSPlaceholderDictionary initWithObjects:forKeys:count:] + 318
    3   CoreFoundation                      0x0000000102d14c3b +[NSDictionary dictionaryWithObjects:forKeys:count:] + 59
    4   libert2                             0x0000000101757eb1 -[ViewController salvaridnofirebase] + 225
    5   libert2                             0x0000000101757b04 -[ViewController viewDidLoad] + 580
    6   UIKit                               0x000000010356af98 -[UIViewController loadViewIfRequired] + 1198
    7   UIKit                               0x000000010356b2e7 -[UIViewController view] + 27
    8   UIKit                               0x0000000103441ab0 -[UIWindow addRootViewControllerViewIfPossible] + 61
    9   UIKit                               0x0000000103442199 -[UIWindow _setHidden:forced:] + 282
    10  UIKit                               0x0000000103453c2e -[UIWindow makeKeyAndVisible] + 42
    11  UIKit                               0x00000001033cc663 -[UIApplication _callInitializationDelegatesForMainScene:transitionContext:] + 4131
    12  UIKit                               0x00000001033d2cc6 -[UIApplication _runWithMainScene:transitionContext:completion:] + 1760
    13  UIKit                               0x00000001033cfe7b -[UIApplication workspaceDidEndTransaction:] + 188
    14  FrontBoardServices                  0x00000001061c5754 -[FBSSerialQueue _performNext] + 192
    15  FrontBoardServices                  0x00000001061c5ac2 -[FBSSerialQueue _performNextFromRunLoopSource] + 45
    16  CoreFoundation                      0x0000000102d2ba31 __CFRUNLOOP_IS_CALLING_OUT_TO_A_SOURCE0_PERFORM_FUNCTION__ + 17
    17  CoreFoundation                      0x0000000102d2195c __CFRunLoopDoSources0 + 556
    18  CoreFoundation                      0x0000000102d20e13 __CFRunLoopRun + 867
    19  CoreFoundation                      0x0000000102d20828 CFRunLoopRunSpecific + 488
    20  UIKit                               0x00000001033cf7cd -[UIApplication _run] + 402
    21  UIKit                               0x00000001033d4610 UIApplicationMain + 171
    22  libert2                             0x000000010175849f main + 111
    23  libdyld.dylib                       0x0000000104a4f92d start + 1
)
libc++abi.dylib: terminating with uncaught exception of type NSException
(lldb) 

以下是方法:

-(void)salvaridnofirebase {
    Firebase *ref = [[Firebase alloc] initWithUrl:@"-myFirebaseURL-"];
    Firebase *usersRef = [ref childByAppendingPath:@"users"];
    NSDictionary *dict = @{ userid: userid };
    [usersRef updateChildValues:dict];
} 

1 个答案:

答案 0 :(得分:0)

你只需要在编码中更加防守。我希望例外情况如下所示:

free

-(void)salvaridnofirebase { Firebase *ref = [[Firebase alloc] initWithUrl:@"-myFirebaseURL-"]; Firebase *usersRef = [ref childByAppendingPath:@"users"]; NSDictionary *dict = @{ userid: userid }; // HERE [usersRef updateChildValues:dict]; } 。因此:

userid == nil

最好还是在-(void)salvaridnofirebase { if (userid == nil) { NSLog(@"Cannot update userid as it's nil"); return; } Firebase *ref = [[Firebase alloc] initWithUrl:@"-myFirebaseURL-"]; Firebase *usersRef = [ref childByAppendingPath:@"users"]; NSDictionary *dict = @{ userid: userid }; [usersRef updateChildValues:dict]; } 时不要调用此方法。你有完全控制权。