• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
best design for error reporting system?
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

best design for error reporting system?


  • Subject: best design for error reporting system?
  • From: has <email@hidden>
  • Date: Sun, 11 Feb 2007 14:54:26 +0000

Hi all,

Looking for advice on the best way to do error reporting in objc- appscript (an ObjC-Apple event bridge) - specifically errors generated by the applications being scripted.

Quick background: sending Apple events is a multi-step process:

1. create a new Apple event
2. add parameters and/or attributes (if any)
3. send the event and wait for a reply
4. check the reply event for error information or a result value (if any)


In higher-level languages like Python and Ruby that support optional method arguments and exception raising as the norm, appscript's public API can perform all four steps in a single method call, e.g.:

app('TextEdit').set(app.documents.first.text, to='Hello world') # will raise CommandError exception if unsuccessful

ObjC, however, doesn't do optional arguments and (if I understand correctly) exceptions should be reserved for only the most serious program errors, so for objc-appscript I'm going with a more granular approach:

    ref = [[[TEApp documents] first] text];

command = [textedit set: ref]; // 1. create event
[command to: @"Hello World"]; // 2. add any keyword parameters
result = [command send]; // 3. send event and return result or report application error



Being a bit of an ObjC noob I'm not sure how best to design the API for that last step though. Here are the schemes currently under consideration:


1. If the command fails (e.g. because TextEdit didn't have any open documents), have -send return nil. Users can then use the command object's -errorNumber and -errorString methods to obtain specific error information if they need it. This allows users to write code that looks like:

    id command = [[textedit set: ref] to: @"Hello World"];
    id result = [command send];
    if (!result)
        OSErr errNum = [command errorNumber];


2. Provide a -sendWithError:(NSDictionary **)error method instead of/ in addition to -send. I know this idiom is sometimes used in the Cocoa APIs so may be more familiar to users. This would allow users to write code that looks like:


    NSDictionary *err;
    [[[textedit set: ref] to: @"Hello World"] sendWithError: &err];
    if (err)
        OSErr errNum = [err objectForKey: @"number"];


3. Have -send automatically throw an exception when a command fails.


4. Some combination of the above; if necessary providing some sort of API call that allows clients to specify which scheme they want to use (either globally or on a per-application or per-event basis).



Anyone have any thoughts/suggestions/criticisms on this? At the moment, appscript uses the first approach (and there's an example of use in the demo project if you want to try it out), but I could easily change to, or add, a different mechanism if needed.


Thanks,

has
--
http://appscript.sourceforge.net
http://rb-appscript.rubyforge.org
http://appscript.sourceforge.net/objc-appscript.html

_______________________________________________

Cocoa-dev mailing list (email@hidden)

Do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com

Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden


  • Prev by Date: Running from DMG
  • Next by Date: Re: Running from DMG
  • Previous by thread: Re: Running from DMG
  • Next by thread: [Q] Cocoa Object : Behavior when "retain" and "copy"?
  • Index(es):
    • Date
    • Thread