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
}
Please don’t do this. From the Apple Docs…
See also the top answer to this question:
When porting Java code to ObjC, how best to represent checked exceptions?