4 @implementation TPCTLObjectiveC
6 + (BOOL)catchNSException:(void(^)(void))block error:(NSError**)error {
11 @catch(NSException* exception) {
13 NSMutableDictionary* ui = exception.userInfo ? [exception.userInfo mutableCopy] : [NSMutableDictionary dictionary];
14 if(exception.reason) {
15 ui[NSLocalizedDescriptionKey] = exception.reason;
17 *error = [NSError errorWithDomain:exception.name code:0 userInfo:ui];
23 + (NSString* _Nullable)jsonSerialize:(id)something error:(NSError**)error {
25 NSError* localError = nil;
26 NSData* jsonData = [NSJSONSerialization dataWithJSONObject:something options:(NSJSONWritingPrettyPrinted | NSJSONWritingSortedKeys) error:&localError];
27 if(!jsonData || localError) {
34 NSString* utf8String = [[NSString alloc] initWithData:jsonData encoding:NSUTF8StringEncoding];
37 *error = [NSError errorWithDomain:@"text" code:0 userInfo:@{NSLocalizedDescriptionKey: @"JSON data could not be decoded as UTF8"}];
43 @catch(NSException* exception) {
45 NSMutableDictionary* ui = exception.userInfo ? [exception.userInfo mutableCopy] : [NSMutableDictionary dictionary];
46 if(exception.reason) {
47 ui[NSLocalizedDescriptionKey] = exception.reason;
49 *error = [NSError errorWithDomain:exception.name code:0 userInfo:ui];