必威-必威-欢迎您

必威,必威官网企业自成立以来,以策略先行,经营致胜,管理为本的商,业推广理念,一步一个脚印发展成为同类企业中经营范围最广,在行业内颇具影响力的企业。

一、什么是异常,发现程序就直接挂了

2019-09-16 00:02 来源:未知

后天清早晨班,开掘前后相继就径直挂了,前几日调得杰出的,怎么来上班就挂了呢?

Terminating app due to uncaught exception 'CALayerInvalidGeometry', reason: 'CALayer position contains NaN: [nan 40]

栈音信打字与印刷如下:

2015-10-20 10:01:12.871 Putaoji[49129:1691777] *** Terminating app due to uncaught exception 'CALayerInvalidGeometry', reason: 'CALayer position contains NaN: [nan 40]'
*** First throw call stack:
(
    0   CoreFoundation                      0x000000010df49f65 __exceptionPreprocess + 165
    1   libobjc.A.dylib                     0x000000010d244deb objc_exception_throw + 48
    2   CoreFoundation                      0x000000010df49e9d +[NSException raise:format:] + 205
    3   QuartzCore                          0x000000010cc2f7e6 _ZN2CA5Layer12set_positionERKNS_4Vec2IdEEb + 152
    4   QuartzCore                          0x000000010cc2f959 -[CALayer setPosition:] + 44
    5   QuartzCore                          0x000000010cc2ffbd -[CALayer setFrame:] + 650
    6   UIKit                               0x000000010e9673f7 -[UIView(Geometry) setFrame:] + 356
    7   UIKit                               0x000000010ec50422 -[UIButton _setFrame:deferLayout:] + 125
    8   UIKit                               0x000000010ec50522 -[UIButton setFrame:] + 178
    9   Putaoji                             0x000000010ae41132 -[PTJInviteFriendsViewController createShareButtonWithFrame:atIndex:title:imageName:] + 690
    10  Putaoji                             0x000000010ae4004b -[PTJInviteFriendsViewController setupUI] + 2715
    11  Putaoji                             0x000000010ae3f5a4 -[PTJInviteFriendsViewController viewDidLoad] + 228
    12  UIKit                               0x000000010ea59931 -[UIViewController loadViewIfRequired] + 1344
    13  UIKit                               0x000000010ea5f923 -[UIViewController __viewWillAppear:] + 120
    14  UIKit                               0x000000010ea8f18a -[UINavigationController _startCustomTransition:] + 1177
    15  UIKit                               0x000000010ea9e7c7 -[UINavigationController _startDeferredTransitionIfNeeded:] + 712
    16  UIKit                               0x000000010ea9f67d -[UINavigationController __viewWillLayoutSubviews] + 57
    17  UIKit                               0x000000010ec3763d -[UILayoutContainerView layoutSubviews] + 248
    18  UIKit                               0x000000010e97f11c -[UIView(CALayerDelegate) layoutSublayersOfLayer:] + 710
    19  QuartzCore                          0x000000010cc3836a -[CALayer layoutSublayers] + 146
    20  QuartzCore                          0x000000010cc2cbd0 _ZN2CA5Layer16layout_if_neededEPNS_11TransactionE + 366
    21  QuartzCore                          0x000000010cc2ca4e _ZN2CA5Layer28layout_and_display_if_neededEPNS_11TransactionE + 24
    22  QuartzCore                          0x000000010cc211d5 _ZN2CA7Context18commit_transactionEPNS_11TransactionE + 277
    23  QuartzCore                          0x000000010cc4e9f0 _ZN2CA11Transaction6commitEv + 508
    24  UIKit                               0x000000010e8f853a _afterCACommitHandler + 174
    25  CoreFoundation                      0x000000010de759d7 __CFRUNLOOP_IS_CALLING_OUT_TO_AN_OBSERVER_CALLBACK_FUNCTION__ + 23
    26  CoreFoundation                      0x000000010de75947 __CFRunLoopDoObservers + 391
    27  CoreFoundation                      0x000000010de6b59b __CFRunLoopRun + 1147
    28  CoreFoundation                      0x000000010de6ae98 CFRunLoopRunSpecific + 488
    29  GraphicsServices                    0x0000000112b04ad2 GSEventRunModal + 161
    30  UIKit                               0x000000010e8ce676 UIApplicationMain + 171
    31  Putaoji                             0x000000010af306ff main + 111
    32  libdyld.dylib                       0x000000010fe9d92d start + 1
)
libc++abi.dylib: terminating with uncaught exception of type NSException
(lldb)

消除措施:
野趣是说程序崩溃是CALayer的岗位中富含子虚乌有的数,说白了正是您的View.frame 中总计的时候,有的地点除以0了。

Terminating app due to uncaught exception 'CALayerInvalidGeometry', reason: 'CALayer position contains NaN: [nan 40]

栈音讯打字与印刷如下:

2015-10-20 10:01:12.871 Putaoji[49129:1691777] *** Terminating app due to uncaught exception 'CALayerInvalidGeometry', reason: 'CALayer position contains NaN: [nan 40]'
*** First throw call stack:
(
    0   CoreFoundation                      0x000000010df49f65 __exceptionPreprocess + 165
    1   libobjc.A.dylib                     0x000000010d244deb objc_exception_throw + 48
    2   CoreFoundation                      0x000000010df49e9d +[NSException raise:format:] + 205
    3   QuartzCore                          0x000000010cc2f7e6 _ZN2CA5Layer12set_positionERKNS_4Vec2IdEEb + 152
    4   QuartzCore                          0x000000010cc2f959 -[CALayer setPosition:] + 44
    5   QuartzCore                          0x000000010cc2ffbd -[CALayer setFrame:] + 650
    6   UIKit                               0x000000010e9673f7 -[UIView(Geometry) setFrame:] + 356
    7   UIKit                               0x000000010ec50422 -[UIButton _setFrame:deferLayout:] + 125
    8   UIKit                               0x000000010ec50522 -[UIButton setFrame:] + 178
    9   Putaoji                             0x000000010ae41132 -[PTJInviteFriendsViewController createShareButtonWithFrame:atIndex:title:imageName:] + 690
    10  Putaoji                             0x000000010ae4004b -[PTJInviteFriendsViewController setupUI] + 2715
    11  Putaoji                             0x000000010ae3f5a4 -[PTJInviteFriendsViewController viewDidLoad] + 228
    12  UIKit                               0x000000010ea59931 -[UIViewController loadViewIfRequired] + 1344
    13  UIKit                               0x000000010ea5f923 -[UIViewController __viewWillAppear:] + 120
    14  UIKit                               0x000000010ea8f18a -[UINavigationController _startCustomTransition:] + 1177
    15  UIKit                               0x000000010ea9e7c7 -[UINavigationController _startDeferredTransitionIfNeeded:] + 712
    16  UIKit                               0x000000010ea9f67d -[UINavigationController __viewWillLayoutSubviews] + 57
    17  UIKit                               0x000000010ec3763d -[UILayoutContainerView layoutSubviews] + 248
    18  UIKit                               0x000000010e97f11c -[UIView(CALayerDelegate) layoutSublayersOfLayer:] + 710
    19  QuartzCore                          0x000000010cc3836a -[CALayer layoutSublayers] + 146
    20  QuartzCore                          0x000000010cc2cbd0 _ZN2CA5Layer16layout_if_neededEPNS_11TransactionE + 366
    21  QuartzCore                          0x000000010cc2ca4e _ZN2CA5Layer28layout_and_display_if_neededEPNS_11TransactionE + 24
    22  QuartzCore                          0x000000010cc211d5 _ZN2CA7Context18commit_transactionEPNS_11TransactionE + 277
    23  QuartzCore                          0x000000010cc4e9f0 _ZN2CA11Transaction6commitEv + 508
    24  UIKit                               0x000000010e8f853a _afterCACommitHandler + 174
    25  CoreFoundation                      0x000000010de759d7 __CFRUNLOOP_IS_CALLING_OUT_TO_AN_OBSERVER_CALLBACK_FUNCTION__ + 23
    26  CoreFoundation                      0x000000010de75947 __CFRunLoopDoObservers + 391
    27  CoreFoundation                      0x000000010de6b59b __CFRunLoopRun + 1147
    28  CoreFoundation                      0x000000010de6ae98 CFRunLoopRunSpecific + 488
    29  GraphicsServices                    0x0000000112b04ad2 GSEventRunModal + 161
    30  UIKit                               0x000000010e8ce676 UIApplicationMain + 171
    31  Putaoji                             0x000000010af306ff main + 111
    32  libdyld.dylib                       0x000000010fe9d92d start + 1
)
libc++abi.dylib: terminating with uncaught exception of type NSException
(lldb)

解决方法:
意思是说程序崩溃是CALayer的职位中满含官样文章的数,说白了就是您的View.frame 中计算的时候,有的地点除以0了。

Terminating app due to uncaught exception 'CALayerInvalidGeometry', reason: 'CALayer position contains NaN: [nan 40]

栈音讯打字与印刷如下:

2015-10-20 10:01:12.871 Putaoji[49129:1691777] *** Terminating app due to uncaught exception 'CALayerInvalidGeometry', reason: 'CALayer position contains NaN: [nan 40]'
*** First throw call stack:
(
    0   CoreFoundation                      0x000000010df49f65 __exceptionPreprocess + 165
    1   libobjc.A.dylib                     0x000000010d244deb objc_exception_throw + 48
    2   CoreFoundation                      0x000000010df49e9d +[NSException raise:format:] + 205
    3   QuartzCore                          0x000000010cc2f7e6 _ZN2CA5Layer12set_positionERKNS_4Vec2IdEEb + 152
    4   QuartzCore                          0x000000010cc2f959 -[CALayer setPosition:] + 44
    5   QuartzCore                          0x000000010cc2ffbd -[CALayer setFrame:] + 650
    6   UIKit                               0x000000010e9673f7 -[UIView(Geometry) setFrame:] + 356
    7   UIKit                               0x000000010ec50422 -[UIButton _setFrame:deferLayout:] + 125
    8   UIKit                               0x000000010ec50522 -[UIButton setFrame:] + 178
    9   Putaoji                             0x000000010ae41132 -[PTJInviteFriendsViewController createShareButtonWithFrame:atIndex:title:imageName:] + 690
    10  Putaoji                             0x000000010ae4004b -[PTJInviteFriendsViewController setupUI] + 2715
    11  Putaoji                             0x000000010ae3f5a4 -[PTJInviteFriendsViewController viewDidLoad] + 228
    12  UIKit                               0x000000010ea59931 -[UIViewController loadViewIfRequired] + 1344
    13  UIKit                               0x000000010ea5f923 -[UIViewController __viewWillAppear:] + 120
    14  UIKit                               0x000000010ea8f18a -[UINavigationController _startCustomTransition:] + 1177
    15  UIKit                               0x000000010ea9e7c7 -[UINavigationController _startDeferredTransitionIfNeeded:] + 712
    16  UIKit                               0x000000010ea9f67d -[UINavigationController __viewWillLayoutSubviews] + 57
    17  UIKit                               0x000000010ec3763d -[UILayoutContainerView layoutSubviews] + 248
    18  UIKit                               0x000000010e97f11c -[UIView(CALayerDelegate) layoutSublayersOfLayer:] + 710
    19  QuartzCore                          0x000000010cc3836a -[CALayer layoutSublayers] + 146
    20  QuartzCore                          0x000000010cc2cbd0 _ZN2CA5Layer16layout_if_neededEPNS_11TransactionE + 366
    21  QuartzCore                          0x000000010cc2ca4e _ZN2CA5Layer28layout_and_display_if_neededEPNS_11TransactionE + 24
    22  QuartzCore                          0x000000010cc211d5 _ZN2CA7Context18commit_transactionEPNS_11TransactionE + 277
    23  QuartzCore                          0x000000010cc4e9f0 _ZN2CA11Transaction6commitEv + 508
    24  UIKit                               0x000000010e8f853a _afterCACommitHandler + 174
    25  CoreFoundation                      0x000000010de759d7 __CFRUNLOOP_IS_CALLING_OUT_TO_AN_OBSERVER_CALLBACK_FUNCTION__ + 23
    26  CoreFoundation                      0x000000010de75947 __CFRunLoopDoObservers + 391
    27  CoreFoundation                      0x000000010de6b59b __CFRunLoopRun + 1147
    28  CoreFoundation                      0x000000010de6ae98 CFRunLoopRunSpecific + 488
    29  GraphicsServices                    0x0000000112b04ad2 GSEventRunModal + 161
    30  UIKit                               0x000000010e8ce676 UIApplicationMain + 171
    31  Putaoji                             0x000000010af306ff main + 111
    32  libdyld.dylib                       0x000000010fe9d92d start + 1
)
libc++abi.dylib: terminating with uncaught exception of type NSException
(lldb)

消除措施:
情趣是说程序崩溃是CALayer的地方中含有一纸空文的数,说白了便是您的View.frame 中总括的时候,有的地点除以0了。

目录:

栈音信打字与印刷如下:

  一、什么是不行?

2015-10-20 10:01:12.871 Putaoji[49129:1691777] *** Terminating app due to uncaught exception 'CALayerInvalidGeometry', reason: 'CALayer position contains NaN: [nan 40]' *** First throw call stack: ( 0 CoreFoundation 0x000000010df49f65 __exceptionPreprocess + 165 1 libobjc.A.dylib 0x000000010d244deb objc_exception_throw + 48 2 CoreFoundation 0x000000010df49e9d +[NSException raise:format:] + 205 3 QuartzCore 0x000000010cc2f7e6 _ZN2CA5Layer12set_positionERKNS_4Vec2IdEEb + 152 4 QuartzCore 0x000000010cc2f959 -[CALayer setPosition:] + 44 5 QuartzCore 0x000000010cc2ffbd -[CALayer setFrame:] + 650 6 UIKit 0x000000010e9673f7 -[UIView setFrame:] + 356 7 UIKit 0x000000010ec50422 -[UIButton _setFrame:deferLayout:] + 125 8 UIKit 0x000000010ec50522 -[UIButton setFrame:] + 178 9 Putaoji 0x000000010ae41132 -[PTJInviteFriendsViewController createShareButtonWithFrame:atIndex:title:imageName:] + 690 10 Putaoji 0x000000010ae4004b -[PTJInviteFriendsViewController setupUI] + 2715 11 Putaoji 0x000000010ae3f5a4 -[PTJInviteFriendsViewController viewDidLoad] + 228 12 UIKit 0x000000010ea59931 -[UIViewController loadViewIfRequired] + 1344 13 UIKit 0x000000010ea5f923 -[UIViewController __viewWillAppear:] + 120 14 UIKit 0x000000010ea8f18a -[UINavigationController _startCustomTransition:] + 1177 15 UIKit 0x000000010ea9e7c7 -[UINavigationController _startDeferredTransitionIfNeeded:] + 712 16 UIKit 0x000000010ea9f67d -[UINavigationController __viewWillLayoutSubviews] + 57 17 UIKit 0x000000010ec3763d -[UILayoutContainerView layoutSubviews] + 248 18 UIKit 0x000000010e97f11c -[UIView(CALayerDelegate) layoutSublayersOfLayer:] + 710 19 QuartzCore 0x000000010cc3836a -[CALayer layoutSublayers] + 146 20 QuartzCore 0x000000010cc2cbd0 _ZN2CA5Layer16layout_if_neededEPNS_11TransactionE + 366 21 QuartzCore 0x000000010cc2ca4e _ZN2CA5Layer28layout_and_display_if_neededEPNS_11TransactionE + 24 22 QuartzCore 0x000000010cc211d5 _ZN2CA7Context18commit_transactionEPNS_11TransactionE + 277 23 QuartzCore 0x000000010cc4e9f0 _ZN2CA11Transaction6commitEv + 508 24 UIKit 0x000000010e8f853a _afterCACommitHandler + 174 25 CoreFoundation 0x000000010de759d7 __CFRUNLOOP_IS_CALLING_OUT_TO_AN_OBSERVER_CALLBACK_FUNCTION__ + 23 26 CoreFoundation 0x000000010de75947 __CFRunLoopDoObservers + 391 27 CoreFoundation 0x000000010de6b59b __CFRunLoopRun + 1147 28 CoreFoundation 0x000000010de6ae98 CFRunLoopRunSpecific + 488 29 GraphicsServices 0x0000000112b04ad2 GSEventRunModal + 161 30 UIKit 0x000000010e8ce676 UIApplicationMain + 171 31 Putaoji 0x000000010af306ff main + 111 32 libdyld.dylib 0x000000010fe9d92d start + 1 ) libc++abi.dylib: terminating with uncaught exception of type NSException

  二、卓殊的总括

化解方法:

  三、课时32课后习题及答案

其实标题已经很驾驭的写到:>*** Terminating app due to uncaught exception 'CALayerInvalidGeometry', reason: 'CALayer position contains NaN: [nan 40]'

 

乐趣是说程序崩溃是CALayer的地点中隐含不设有的数,说白了正是你的View.frame 中总计的时候,有的地点除以0了。比方在自家的次第中总计的时候:

*******************

 CGFloat leftSpace = 24.0f; CGFloat width = SCREENWIDTH; CGFloat itemWH = 80.0-22.0; NSInteger count = shareTitleArray.count; CGFloat innerSpace = (width -leftSpace*2 - itemWH *count)/(shareTitleArray.count -1); for (int i = 0; i<shareTitleArray.count; i++) { CGFloat x = leftSpace+i*(innerSpace+itemWH); CGRect frame = CGRectMake(x, 11, itemWH, itemWH); [self createShareButtonWithFrame:frame atIndex:i title:shareTitleArray[i] imageName:shareImageArray[i]]; }

一、什么是老大?

全面一看未有何样难题,不过假如shareTitleArray数组中的个数为1的气象的下,就能够产生除以0,进而致使程序崩溃。

*******************

总括一下,如果程序总出现上述崩溃信息,就是在某个地方除以0了

程序出现逻辑错误大概客商输入违法都会孳生非常,但那些特别实际不是致命的,不会招致程序崩溃死掉。能够应用Python提供的老大处理体制,在非常出现的时候立刻抓获,并从里边消食掉。

那么什么样是那二个呢?举个例证:

file_name = input("请输入要打开的文件名:")
f = open(file_name,'r')
print("文件的内容是:")

for each_line in f:
      print(each_line)

这里当然假使顾客输入的是科学的,但假使客户输入一个荒诞不经的文件名,那么位置的代码就软弱:

TAG标签:
版权声明:本文由必威发布于必威-编程,转载请注明出处:一、什么是异常,发现程序就直接挂了