mirror of https://github.com/oxen-io/session-ios
You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
47 lines
1.4 KiB
Objective-C
47 lines
1.4 KiB
Objective-C
//
|
|
// Copyright (c) 2018 Open Whisper Systems. All rights reserved.
|
|
//
|
|
|
|
#import "SCKExceptionWrapper.h"
|
|
#import <SessionProtocolKit/OWSAsserts.h>
|
|
|
|
NS_ASSUME_NONNULL_BEGIN
|
|
|
|
NSErrorDomain const SCKExceptionWrapperErrorDomain = @"SignalCoreKit.SCKExceptionWrapper";
|
|
NSErrorUserInfoKey const SCKExceptionWrapperUnderlyingExceptionKey = @"SCKExceptionWrapperUnderlyingException";
|
|
|
|
NSError *SCKExceptionWrapperErrorMake(NSException *exception)
|
|
{
|
|
return [NSError errorWithDomain:SCKExceptionWrapperErrorDomain
|
|
code:SCKExceptionWrapperErrorThrown
|
|
userInfo:@{ SCKExceptionWrapperUnderlyingExceptionKey : exception }];
|
|
}
|
|
|
|
@implementation SCKExceptionWrapper
|
|
|
|
+ (BOOL)tryBlock:(void (^)(void))block error:(NSError **)outError
|
|
{
|
|
OWSAssertDebug(outError);
|
|
@try {
|
|
block();
|
|
return YES;
|
|
} @catch (NSException *exception) {
|
|
*outError = SCKExceptionWrapperErrorMake(exception);
|
|
return NO;
|
|
}
|
|
}
|
|
|
|
@end
|
|
|
|
void SCKRaiseIfExceptionWrapperError(NSError *_Nullable error)
|
|
{
|
|
if (error && [error.domain isEqualToString:SCKExceptionWrapperErrorDomain]
|
|
&& error.code == SCKExceptionWrapperErrorThrown) {
|
|
NSException *_Nullable exception = error.userInfo[SCKExceptionWrapperUnderlyingExceptionKey];
|
|
OWSCAssert(exception);
|
|
@throw exception;
|
|
}
|
|
}
|
|
|
|
NS_ASSUME_NONNULL_END
|