• 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
Re: NSException category?
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: NSException category?


  • Subject: Re: NSException category?
  • From: Uli Kusterer <email@hidden>
  • Date: Thu, 06 Feb 2014 21:05:21 +0100

On 06 Feb 2014, at 19:44, Carl Hoefs <email@hidden> wrote:
> I would like to be able to add additional context info to certain exceptions that the system might generate. Since NSException's userInfo dict is nil in such cases it would be convenient to add an error context dict to the exception and then handle/display it.
>
>  @try {
>    ...;
>  }
>  @catch (NSException *e) {
>    e.userInfo = [NSDictionary dictionaryWithObject:@"Unsupported session resolution"
>                                             andKey:@"Context"];
>        --> No setter method "setUserInfo:" for assignment to property
>    [ self showException: e ];
>  }
>  @finally {
>    ...;
>  }
>
> Unfortunately I can't just add my own userInfo dict onto the exception, as there is no setter for it by default. Would it be heresy to create an NSException category to implement the -setUserInfo: method to do this? What is a better way to handle this?


 What NSError does in this case is create a new object and attach the old one to its userInfo (In the case of NSError using an NSUnderlyingErrorKey). That sounds like a better approach than trying to modify (or replace) the userInfo in the original error, which might surprise you later on or lose you data if Apple ever decides to put stuff in the userInfo after all..

-- Uli Kusterer
"The Witnesses of TeachText are everywhere..."




_______________________________________________

Cocoa-dev mailing list (email@hidden)

Please 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


  • Follow-Ups:
    • Re: NSException category?
      • From: Carl Hoefs <email@hidden>
References: 
 >NSException category? (From: Carl Hoefs <email@hidden>)

  • Prev by Date: Re: NSException category?
  • Next by Date: Re: NSException category?
  • Previous by thread: Re: NSException category?
  • Next by thread: Re: NSException category?
  • Index(es):
    • Date
    • Thread