LoginSignup
0
0

More than 5 years have passed since last update.

Objective-C 例外の出力方法

Last updated at Posted at 2017-11-22

備忘録として、
try~catchで発生した例外の内容をログに出力する。

サンプル

Objective-C
@try {
    
    // Code to crash
    NSArray *hoge = [NSArray array];
    [hoge objectAtIndex:0];
    
} @catch (NSException *e) {
    NSLog(@"\n%@\n%@\n%@\n", e.name, e.reason, e.callStackSymbols);
}

ログ

Log
NSRangeException
*** -[__NSArray0 objectAtIndex:]: index 0 beyond bounds for empty NSArray
(
	0   CoreFoundation                      0x000000010ebf41ab __exceptionPreprocess + 171
	1   libobjc.A.dylib                     0x000000010e289f41 objc_exception_throw + 48
	2   CoreFoundation                      0x000000010ec0cf3d -[__NSArray0 objectAtIndex:] + 93
	3   HogeSampleTests                     0x0000000125ecbf98 -[HogeSampleTests testExample] + 88
	4   CoreFoundation                      0x000000010eb7849c __invoking___ + 140
	5   CoreFoundation                      0x000000010eb78370 -[NSInvocation invoke] + 320
	6   XCTest                              0x00000001242b9125 __24-[XCTestCase invokeTest]_block_invoke + 591
	7   XCTest                              0x0000000124301a52 -[XCUITestContext performInScope:] + 183
	8   XCTest                              0x00000001242b8ecb -[XCTestCase invokeTest] + 141
	9   XCTest                              0x00000001242b9e8c __26-[XCTestCase performTest:]_block_invoke.369 + 42
	10  XCTest                              0x00000001243067f9 +[XCTContext runInContextForTestCase:block:] + 163
	11  XCTest                              0x00000001242b9828 -[XCTestCase performTest:] + 608
	12  XCTest                              0x00000001242b582e __27-[XCTestSuite performTest:]_block_invoke + 363
	13  XCTest                              0x00000001242b5195 -[XCTestSuite _performProtectedSectionForTest:testSection:] + 26
	14  XCTest                              0x00000001242b5392 -[XCTestSuite performTest:] + 239
	15  XCTest                              0x00000001242b582e __27-[XCTestSuite performTest:]_block_invoke + 363
	16  XCTest                              0x00000001242b5195 -[XCTestSuite _performProtectedSectionForTest:testSection:] + 26
	17  XCTest                              0x00000001242b5392 -[XCTestSuite performTest:] + 239
	18  XCTest                              0x00000001242b582e __27-[XCTestSuite performTest:]_block_invoke + 363
	19  XCTest                              0x00000001242b5195 -[XCTestSuite _performProtectedSectionForTest:testSection:] + 26
	20  XCTest                              0x00000001242b5392 -[XCTestSuite performTest:] + 239
	21  XCTest                              0x000000012430df23 __44-[XCTTestRunSession runTestsAndReturnError:]_block_invoke + 40
	22  XCTest                              0x00000001242c8a0e -[XCTestObservationCenter _observeTestExecutionForBlock:] + 475
	23  XCTest                              0x000000012430ddc2 -[XCTTestRunSession runTestsAndReturnError:] + 281
	24  XCTest                              0x00000001242a4e87 -[XCTestDriver runTestsAndReturnError:] + 314
	25  XCTest                              0x0000000124305a64 _XCTestMain + 619
	26  CoreFoundation                      0x000000010eb9718c __CFRUNLOOP_IS_CALLING_OUT_TO_A_BLOCK__ + 12
	27  CoreFoundation                      0x000000010eb7b96b __CFRunLoopDoBlocks + 203
	28  CoreFoundation                      0x000000010eb7b144 __CFRunLoopRun + 1300
	29  CoreFoundation                      0x000000010eb7a9b9 CFRunLoopRunSpecific + 409
	30  GraphicsServices                    0x0000000113ca59c6 GSEventRunModal + 62
	31  UIKit                               0x000000010f06f5e8 UIApplicationMain + 159
	32  HogeSample                          0x000000010d16d67f main + 111
	33  libdyld.dylib                       0x00000001114f2d81 start + 1
)
0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0