nsexception

Xcode - Terminating with uncaught exception of type NSException when a button is pressed

天大地大妈咪最大 提交于 2019-12-20 02:29:44
问题 I'm new to app development and I'm following Apple's tutorial to learn. I've looked through a lot of questions asked about this type of error but none of them are helping me. In the tutorial, I'm stuck on the "Add Buttons to the View" section where I'm trying to implement a string to be printed out on the console when a button is tapped/clicked on. Only I get an error when doing so. My code for the button in Swift: import UIKit class StarRatingControl: UIView { // MARK: Initialization

NSException raise:format: as the last statement in a method

只谈情不闲聊 提交于 2019-12-19 22:03:56
问题 I have this method: + (MHTwitterParser*)createParser:(NSString*)format { if ([format compare:@"json"] == NSOrderedSame) { return [[MHJsonTwitterParser alloc] init]; } [NSException raise:@"Unknown format" format:@"Unknown format of parser"]; } Compiler complains that: Control may reach end of non-void function It is just a warning, but it does not matter. Obvious fix for that is to add for example return nil; after the [NSException raise: ... . However, I think it is not needed (and is even

@try - catch block in Objective-C

北城以北 提交于 2019-12-17 17:25:23
问题 Why doesn't @try block work? It crashed the app, but it was supposed to be caught by the @try block. NSString* test = [NSString stringWithString:@"ss"]; @try { [test characterAtIndex:6]; } @catch (NSException * e) { NSLog(@"Exception: %@", e); } @finally { NSLog(@"finally"); } 回答1: All work perfectly :) NSString *test = @"test"; unichar a; int index = 5; @try { a = [test characterAtIndex:index]; } @catch (NSException *exception) { NSLog(@"%@", exception.reason); NSLog(@"Char at index %d

Usage of NSException in iPhone Apps

你说的曾经没有我的故事 提交于 2019-12-17 10:30:37
问题 One of my friends asked me not to use NSException in iPhone Apps. The reason he gave was "performance bottleneck". But I am not convinced of it. Can someone confirm me that we should restrain from using NSException in iPhone App? If you have best practices for using NSException, please provide that too. UPDATE: This link requests us to use Exception handling at the app level. Have someone ever done it? Please give the advantages of it and any other performance hitches it could create. 回答1: In

Swift Error - “Unrecognized selector sent to instance”

本小妞迷上赌 提交于 2019-12-13 10:35:47
问题 I am working on a Swift project in Xcode v6.1.1, and I am getting the following error that I don't understand. I believe there is a problem with a couple of the Labels in my Main.storyboard and/or the UILabel variable I have them connected to. I have tried everything I can find to fix it, and nothing has worked. Any help would be appreciated. 2015-03-02 19:43:14.854 Final Project[7380:250494] -[UILabel longValue]: unrecognized selector sent to instance 0x7b8e1810 2015-03-02 19:43:14.876 Final

Why does this code crash on the distributed app but work in the debugger?

人盡茶涼 提交于 2019-12-12 16:43:56
问题 I have simple code that executes and in case it crashes I want to catch the exception so the app does not crash. @try { x = [self try_doMyWork:Param]; } @catch (NSException* e) { NSLog(@"Exception"); } While this code works in debug and catches the exception (which is a simple index beyond end of array) it crashes in distributed apps on iPhones. Why is this and how can I ensure that it also works on distributed apps? 回答1: Uncaught application-level exceptions are only one cause of crashes.

Getting Exception 'NSRangeException'

半世苍凉 提交于 2019-12-12 13:54:09
问题 I am getting Exception for substringWithRange:range in below method. I am having textview with editing disabled. i am using textfield only for text selection. when i am selecting text for firs time no exception but when i press for second time it throughs. Exception: 'NSRangeException', reason: ' * -[NSCFString substringWithRange:]: Range or index out of bounds'. - (void)textViewDidChangeSelection:(UITextView *)textView { NSRange range = [tv selectedRange]; str = [tv.text substringWithRange

Create NSException from IntPtr

我只是一个虾纸丫 提交于 2019-12-12 03:48:39
问题 I referring to this post: private static void MyUncaughtExceptionHandler(IntPtr exception) { // this is not working because NSException(IntPtr) is a protected constructor var e = new NSException(exception); // ... } How can I create an exception here? Should I do somehting like this? NSException exception = (NSException)ObjCRuntime.Runtime.GetNSObject(handle); 回答1: You found the correct answer yourself: NSException exception = (NSException) ObjCRuntime.Runtime.GetNSObject (handle); 回答2: One

NSInvalidArgumentException not being caught in code

我的未来我决定 提交于 2019-12-12 01:33:44
问题 I'm using selectors to dynamically call functions in Objective-C. My problem is that my @try / @catch block is not catching the exception if I pass an non-existent function name. In the console I get an uncaught NSInvalidArgumentException and further down I get an uncaught NSException . I have tried catching the the two types of exceptions in a standard @try / @catch block but they aren't registering. Xcode won't let me compile if I try to catch NSInvalidArgumentException as it's not a

Adding child progress for multiple file download

时间秒杀一切 提交于 2019-12-10 23:04:15
问题 I'm downloading multiple files using AFNetworking 3.0 in my project. I want to show single download progress of all files. I added each child progress of each file download to the parent progress. But it's not working, app crashed. I'm getting the error - Terminating app due to uncaught exception 'NSInternalInconsistencyException', reason: '<DownloadManager: 0x7f92e2f6e130>: An -observeValueForKeyPath:ofObject:change:context: message was received but not handled. Key path: fractionCompleted