nsexception

What is the lifecycle of an object caught in a @catch block?

 ̄綄美尐妖づ 提交于 2019-12-10 17:24:28
问题 When you catch an exception in an ObjC @catch block, what is the lifecycle of that exception object? I know I can safely use it inside the block, but what if I want to use it again after the block, like this? NSException * exception = nil; @try { // do something risky } @catch(NSException * e) { exception = e; } if (exception) { NSLog(@"Caught exception: %@", exception); } Can I safely stash the reference into another local? Should I be retain, autorelease ing it for safety? Can I retain it

Catch Objective-C exception in Swift

牧云@^-^@ 提交于 2019-12-09 09:40:18
问题 I am trying to set the value of an @objc object in my Swift code using obj.setValue(value, forKey: key) . It works fine when the object has the property being set. But if it doesn't, my app crashes hard with an uncaught NSException ("class is not key value coding-compliant…"). How can I catch and absorb this exception like I can in Objective-C so as to not crash my app? I tried wrapping it in a Swift try-catch, but it complains that none of the instructions throws and does nothing. 回答1: see

libc abi.dylib: terminating with uncaught exception of type NSException CollectionView

给你一囗甜甜゛ 提交于 2019-12-07 07:48:04
问题 when i run my app, i received this error : 2014-08-11 10:52:10.546 ControlViewTest[918:60b] -[UIViewController collectionView:numberOfItemsInSection:]: unrecognized selector sent to instance 0x8c862f0 2014-08-11 10:52:10.605 ControlViewTest[918:60b] * Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[UIViewController collectionView:numberOfItemsInSection:]: unrecognized selector sent to instance 0x8c862f0' * First throw call stack: ( 0 CoreFoundation

How do I know which line of code has caused my iOS app to crash in Xcode 9

ぐ巨炮叔叔 提交于 2019-12-07 02:29:01
问题 I am building an app in Xcode 9 (Swift 4) and it crashes before it even loads completely. I get an error: Thread 1: Signal SIGABRT and libc++abi.dylib: terminating with uncaught exception of type NSException . How do I know which line of code is causing the error using breakpoints and debugging? Any help would be appreciated. Thanks! (Here's a screenshot as well) 回答1: What you need here is an exception breakpoint. An exception breakpoint is a special kind of breakpoint that breaks whenever an

Core Data: Errors vs Exceptions Part 2

China☆狼群 提交于 2019-12-06 11:05:49
问题 My question is similar to this one, but I need further clarification. I often get exceptions during code like this: NSError* error; if (![managedObjectContext save:&error]) { NSLog(@"Failed to save to data store: %@", [error localizedDescription]); } However, when I put a breakpoint in objc_exception_throw , I can find out that an exception is thrown in save : (gdb) po [$eax name] NSInternalInconsistencyException (gdb) po [$eax description] optimistic locking failure I wouldn't expect this,

libc abi.dylib: terminating with uncaught exception of type NSException CollectionView

大憨熊 提交于 2019-12-05 16:08:49
when i run my app, i received this error : 2014-08-11 10:52:10.546 ControlViewTest[918:60b] -[UIViewController collectionView:numberOfItemsInSection:]: unrecognized selector sent to instance 0x8c862f0 2014-08-11 10:52:10.605 ControlViewTest[918:60b] * Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[UIViewController collectionView:numberOfItemsInSection:]: unrecognized selector sent to instance 0x8c862f0' * First throw call stack: ( 0 CoreFoundation 0x017ec1e4 exceptionPreprocess + 180 1 libobjc.A.dylib 0x0156b8e5 objc_exception_throw + 44 2 CoreFoundation

How to get line number, method name, and class name when crash occurs using Objective C

主宰稳场 提交于 2019-12-05 06:33:41
问题 I am developing an app in which I have to track crashes. There is a restriction that I can't use any third party source like Twitter's Fabric framework to handle crash logging. Currently I am only able to get the reason for crash. I am not able to get the exact point of crash. What I am doing: In my app delegate's didFinishLaunchingWithOptions method I had made my own exception handler: NSSetUncaughtExceptionHandler(&uncaughtExceptionHandler); uncaughtExceptionHandler ---- void

How to get line number, method name, and class name when crash occurs using Objective C

馋奶兔 提交于 2019-12-03 21:38:18
I am developing an app in which I have to track crashes. There is a restriction that I can't use any third party source like Twitter's Fabric framework to handle crash logging. Currently I am only able to get the reason for crash. I am not able to get the exact point of crash. What I am doing: In my app delegate's didFinishLaunchingWithOptions method I had made my own exception handler: NSSetUncaughtExceptionHandler(&uncaughtExceptionHandler); uncaughtExceptionHandler ---- void uncaughtExceptionHandler(NSException *exception) { NSLog(@"CRASH: %@", exception); NSLog(@"callStackSymbols: %@",

Catch Objective-C exception in Swift

为君一笑 提交于 2019-12-03 12:21:15
I am trying to set the value of an @objc object in my Swift code using obj.setValue(value, forKey: key) . It works fine when the object has the property being set. But if it doesn't, my app crashes hard with an uncaught NSException ("class is not key value coding-compliant…"). How can I catch and absorb this exception like I can in Objective-C so as to not crash my app? I tried wrapping it in a Swift try-catch, but it complains that none of the instructions throws and does nothing. Casey see this answer : // // ExceptionCatcher.h // #import <Foundation/Foundation.h> NS_INLINE NSException *

iphone - try, catch question

六月ゝ 毕业季﹏ 提交于 2019-12-02 11:43:34
问题 I have a method that has several parts that can throw an exception. If one of these parts fail, I would like the cleaning method to run. I am thinking about using the try/catch directive. My question is: will I have to use one directive for every line of code that can throw an exception or can I simply include the whole method in a block like this? @try { [self doStuff]; // doStuff has several passages that could throw an exception } @catch (NSException * e) { [self cleanTheWholeThing]; } In