Reputation: 37
So I have a program that after a try/catch block occurs I need a modal window to appear so the user can make a specific choice then I would like the program to continue on. I have no Idea how to make this work and I keep getting these exceptions.
*** Assertion failure in -[NSApplication _commonBeginModalSessionForWindow:relativeToWindow:modalDelegate:didEndSelector:contextInfo:], /SourceCache/AppKit/AppKit-1187.34/AppKit.subproj/NSApplication.m:3920
Exception detected while handling key input.
Modal session requires modal window
I have configured my modal sheet to appear in 2 different ways the first way is Via a button press and the 2nd way is after my try catch block. When I make it appear Via a button press that is linked directly to Configure Game
it works fine but when I do it through a try catch block in another method it throws all the exceptions above.
//Method that opens the modal sheet
- (IBAction)configureGame:(id)sender
{
//Calls a webview for the user to go to a specific location
NSString *FGstarter = @"http://www.google.com";
NSURL *FGplayerUrl = [NSURL URLWithString:FGstarter];
[webView setMainFrameURL:[FGplayerUrl absoluteString]];
//Opens the Modal Sheet
[NSApp beginSheet:configureSheet modalForWindow:mainWindow
modalDelegate:self didEndSelector:NULL contextInfo:nil];
}
//Select Method to a Select button which also closes the Sheet
- (IBAction)select:(id)sender{
//sets a NSString Instance Var to the Current URL of the webView
currentPage = [webView stringByEvaluatingJavaScriptFromString:@"window.location.href"]);
//Closes the sheet
[NSApp endSheet:configureSheet];
}
-(NSMutableArray *)loadPlayer:(NSString *)name{
@try {
// Code here might cause exception that gets caught in the catch
}
@catch (NSException *exception) {
//When I call this function I get all the exceptions listed in the top of the post
[self configureGame:nil];
//Ideally here what would happen here is the modal sheet would pop up the user would hit the select button that calls the select method then the program continues running.
}
NSString *page = currentPage;
//...Continue Using this method
}
Upvotes: 0
Views: 481
Reputation: 31745
Please don't do this. From the Apple Docs...
Important In many environments, use of exceptions is fairly commonplace. For example, you might throw an exception to signal that a routine could not execute normally—such as when a file is missing or data could not be parsed correctly. Exceptions are resource-intensive in Objective-C. You should not use exceptions for general flow-control, or simply to signify errors. Instead you should use the return value of a method or function to indicate that an error has occurred, and provide information about the problem in an error object. For more information, see Error Handling Programming Guide.
See also the top answer to this question:
When porting Java code to ObjC, how best to represent checked exceptions?
Upvotes: 1