Re: Reporting errors from key-value-coding accessors
Re: Reporting errors from key-value-coding accessors
- Subject: Re: Reporting errors from key-value-coding accessors
- From: Bill Cheeseman <email@hidden>
- Date: Sat, 20 Aug 2005 09:42:02 -0400
on 2005-08-19 8:17 PM, Mark Alldritt at email@hidden wrote:
>> 2) Getters that may find an error that the UI should display to the
>> user should make an NSError and display it using NSApp or NSWindow's
>> facilities. See <http://developer.apple.com/documentation/Cocoa/
>> Conceptual/ErrorHandlingCocoa/index.html>.
>
> How then is a primitive get accessor to know if it should report an error to
> the UI? It would have to somehow detect how it was called. If the getter
> blindly presents an error in the UI, how is the parallel Cocoa Scripting
> accessor (or any other KVC client) to know that this has happened and/or
> prevent it and report a meaningful error back through Cocoa Scripting?
Perhaps by testing whether [NSScriptCommand currentCommand] is nil? I
haven't actually tried this, but the documentation does say it returns nil
if no script command is currently executing. In that case, the getter could
only have been called from the GUI, right?
If you want to implement the idea of a centralized error dispatching system,
you would implement a method in the central system called something like
-handleError:context:, where context is a string or enumerator constant or
other object that you define to indicate whether it is a GUI error or an
AppleScript error or some other kind of error. In your getter, you would
invoke this method like so:
if ([NSScriptCommand currentCommand] == nil) {
myContext = SDGUIContext;
} else {
mycontext = SDAppleScriptContext;
}
[myCentralErrorHandlingClass handleError:<whatever> context:myContext];
Or, if there are only two possible error contexts, just make the context
parameter a BOOL and do this in the getter:
[myCentralErrorHandlingClass handleError:<whatever>
context:([NSScriptCommand currentCommand] == nil)];
You would need additional parameters, or perhaps a dictionary parameter, to
pass the actual error information. You could eliminate the context parameter
and include that information in the dictionary parameter. These are
implementation details, but I think the basic concept might meet your needs.
--
Bill Cheeseman - email@hidden
Quechee Software, Quechee, Vermont, USA
http://www.quecheesoftware.com
PreFab Software - http://www.prefab.com/scripting.html
The AppleScript Sourcebook - http://www.AppleScriptSourcebook.com
Vermont Recipes - http://www.stepwise.com/Articles/VermontRecipes
_______________________________________________
Do not post admin requests to the list. They will be ignored.
Cocoa-dev mailing list (email@hidden)
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden