0

I am creating static ios library, and want to throw system generated exception as well as custom exception with code and message to user on request failure.

User will import my header files and .a file and call static library methods.

Can somebody tell me what is the easiest and generalize way to handle exception or create own exception and throw back to user, So that user will take specific action by getting code and message.

I have go over the following links, but want to create custom NSError class or NSException class so that i can add my own error code and message, So little bit confused what to do,

How to create custom exception in objective c?

Exception handling in entire application

Please help.

Thanks & Regards,

Community
  • 1
  • 1
Abbas Mulani
  • 703
  • 2
  • 8
  • 19

1 Answers1

0

In general, exception handling is not a safe language mechanism in Objective-C, so you should only use it for programming errors. E.g. you can use [NSException raise:NSInvalidArgumentException format:@"fooIndex out of range. Should be 0..%d, but is %d", (int)self.length, fooIndex];

Michael
  • 6,451
  • 5
  • 31
  • 53
  • But i want generalize way to send custom error message and code to user, and also system errors before application get crash, such that when we are about to get index of empty array,so that user can get it and do appropriate action. Currently i am sending NSDictionary object to user with keys "Message" and "Code". – Abbas Mulani Apr 23 '14 at 14:10