Tuesday, 10 September 2013

What is the correct way to handle an error in awakeFromNib?

What is the correct way to handle an error in awakeFromNib?

In my main application (MyApp) I programmatically create other windows by
creating new instances of a window controller (MyWindowController). When
the window controller is initialised, it loads a window and other
views/objects from a nib file. In the awakeFromNib method on one of these
objects (MyModel), there is some code that may fail, and I would like to
display an error to the user, and destroy the window controller, the
window, and all related objects.
In summary:
Application creates new instance of MyWindowController.
MyWindowController loads a window and other views/objects from a nib file.
During awakeFromNib one of these objects (an instance of MyModel)
encounters a failure.
An error message is displayed to the user, and the instance of
MyWindowController, MyModel, and all other related instances are
destroyed.
How would I accomplish step 4 in the most Cocoa-esque way?

No comments:

Post a Comment