Questions tagged [nsexception]

NSException is a Mac Developer Library class used to implement exception handling and contains information about an exception.

NSException is a Mac Developer Library class used to implement exception handling and contains information about an exception.

It is available in OS X v10.0 and later and is declared in NSException.h

259 questions
200
votes
3 answers

@try - catch block in Objective-C

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:…
Alexandru Circus
  • 5,478
  • 7
  • 52
  • 89
131
votes
5 answers

Xcode doesn't show the line that causes a crash

Every time my app crashes Xcode highlights the UIApicationMain() call in the main() function as the line that caused the crash. In some cases that used to be normal (segmentation fault for example) but the crash I am trying to deal with is a simple…
JonasG
  • 9,274
  • 12
  • 59
  • 88
90
votes
6 answers

Catching NSException in Swift

The following code in Swift raises NSInvalidArgumentException exception: task = NSTask() task.launchPath = "/SomeWrongPath" task.launch() How can I catch the exception? As I understand, try/catch in Swift is for errors thrown within Swift, not for…
silyevsk
  • 4,021
  • 3
  • 31
  • 30
38
votes
3 answers

iOS crash report "unexpected start state" exception?

I have found several crash reports with the reason unexpected start state. My code looks like this: NSRange range = [content rangeOfString:@""]; if (range.location != NSNotFound) { NSString *htmlStr = [content…
tom lider
  • 419
  • 4
  • 4
32
votes
5 answers

An -observeValueForKeyPath:ofObject:change:context: message was received but not handled

I am relatively new to KVO, so there is a good chance that I am violating some fundamental rule. I am using Core Data. My app crashes with the following message: And what I can't understand is why a CGImage is getting involved in observing a value…
westsider
  • 4,967
  • 5
  • 36
  • 51
26
votes
1 answer

How to use XCTAssertThrowsSpecific

I'm writing Cocoa unit tests using XCTest and recently used XCTAssertThrows for the first time. That's pretty cool, but I want to make it even better with XCTAssertThrowsSpecific and requiring a certain exception. Here is an example…
owenfi
  • 2,471
  • 1
  • 24
  • 37
23
votes
3 answers

How to properly handle NSFileHandle exceptions in Swift 2.0?

First of all, I am new to iOS and Swift and come from a background of Android/Java programming. So to me the idea of catching an exception from an attempt to write to a file is second nature, in case of lack of space, file permissions problems, or…
mirage
  • 343
  • 2
  • 8
20
votes
1 answer

Terminating with uncaught exception of type NSException?

My application crashes when clicking a button to go to segue into a new view. This comes up: int main(int argc, char * argv[]) { @autoreleasepool { return UIApplicationMain(argc, argv, nil, NSStringFromClass([AppDelegate class])); …
Logan Larroque
  • 235
  • 1
  • 3
  • 7
19
votes
4 answers

Catch Objective-C exception in Swift

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…
devios1
  • 36,899
  • 45
  • 162
  • 260
18
votes
2 answers

How to find instance by hex in XCode console?

When I bring up console after my iPhone app crashes, it often says "unrecognized selector sent to instance 0x blah blah blah." How can I find out what variable this is? Is there a way in the debugger? Is it even possible? Thanks.
marty
  • 207
  • 3
  • 6
13
votes
1 answer

NSException and NSError custom exception/error

I recently started learning Objective-C, and I am working on an iOS app as an exercise, anyway, I want to handle overflow by throwing exception (I come from a Java background), I searched the reference there is only NSException, but then I read in…
hakuna matata
  • 3,243
  • 13
  • 56
  • 93
11
votes
5 answers

NSUnknownKeyException setValue:forUndefinedKey:

Terminating app due to uncaught exception 'NSUnknownKeyException', reason: '[ setValue:forUndefinedKey:]: this class is not key value coding-compliant for the key buttonOfFirstView.' Why do I get this error? I am trying to make a table cell…
gauravds
  • 2,931
  • 2
  • 28
  • 45
10
votes
3 answers

Usage of NSException in iPhone Apps

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…
RK-
  • 12,099
  • 23
  • 89
  • 155
10
votes
6 answers

Error/Exception handling in a method that returns bool

In my custom framework, I have a method like the one shown below which fetches value from dictionary and converts it into BOOL and returns the boolean value. - (BOOL)getBoolValueForKey:(NSString *)key; What if the caller of this method passes a…
saikamesh
  • 4,569
  • 11
  • 53
  • 93
9
votes
2 answers

Objective-C/iPhone - NSException capturing as much information as possible

I'm using the following code to capture exceptions in my app: void uncaughtExceptionHandler(NSException *exception) { [FlurryAPI logError:@"Uncaught" message:@"Crash!" exception:exception]; } Just wondering whether I can pin-point, line…
gotnull
  • 26,454
  • 22
  • 137
  • 203
1
2 3
17 18