Objective-C: Add an NSString pattern to NSException
source link: https://www.codesd.com/item/objective-c-add-an-nsstring-pattern-to-nsexception.html
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.
Objective-C: Add an NSString pattern to NSException
I am working on some API (Crittercism) to report handled exceptions in the client to server.
The client API takesNSException
as the input parameter. I have to add some application context info string(NSString
) also to theNSException
before calling the API.
How I can do it using Objective-C.
NSString* appContextString;
NSString *test = @"test";
unichar a;
int index = 5;
@try {
a = [test characterAtIndex:index];
}
@catch (NSException *exception) {
// add app context to exception before reporting to Crittercism.
[Crittercism logHandledException:exception];
}
I have to append appContextString to exception.
You could build a new NSException
object from attributes of the old one, but that seems very messy. As you are just logging the handled exception, I would simply log the "app context" before that:
@try {
a = [test characterAtIndex:index];
}
@catch (NSException *exception) {
NSString *appContext = @"...";
[Crittercism leaveBreadcrumb:appContext];
[Crittercism logHandledException:exception];
}
Recommend
About Joyk
Aggregate valuable and interesting links.
Joyk means Joy of geeK