From e9736c95f29efb77b8ce1f5ead8e4fad091cbb1c Mon Sep 17 00:00:00 2001 From: Andrey Kornich Date: Tue, 16 Mar 2021 11:50:39 -0700 Subject: [PATCH] RollbarSwift: addressing PR comments --- .../macosAppSwift/ContentView.swift | 2 +- .../RollbarSwift/RollbarExceptionGuard.m | 55 ++++++++++--------- 2 files changed, 29 insertions(+), 28 deletions(-) diff --git a/Demos/macosAppSwift/macosAppSwift/ContentView.swift b/Demos/macosAppSwift/macosAppSwift/ContentView.swift index 107c79e6..e5dddf33 100644 --- a/Demos/macosAppSwift/macosAppSwift/ContentView.swift +++ b/Demos/macosAppSwift/macosAppSwift/ContentView.swift @@ -83,7 +83,7 @@ func handleSwiftError() { self.generateObjCException(); } - print("Guearded execution succeeded: \(success).") + print("Guarded execution succeeded: \(success).") } func createGuard() -> RollbarExceptionGuard { diff --git a/RollbarSwift/Sources/RollbarSwift/RollbarExceptionGuard.m b/RollbarSwift/Sources/RollbarSwift/RollbarExceptionGuard.m index 66dcabb2..7eb7f344 100644 --- a/RollbarSwift/Sources/RollbarSwift/RollbarExceptionGuard.m +++ b/RollbarSwift/Sources/RollbarSwift/RollbarExceptionGuard.m @@ -8,51 +8,52 @@ #import "RollbarExceptionGuard.h" #import "RollbarTryCatch.h" -@implementation RollbarExceptionGuard { +@implementation RollbarExceptionGuard { @private RollbarLogger *logger; } -(BOOL)tryExecute:(nonnull void(NS_NOESCAPE^)(void))block { + NSError *error = nil; return [self execute:block error:&error]; } -(BOOL)execute:(nonnull void(NS_NOESCAPE^)(void))tryBlock - error:(__autoreleasing NSError * _Nullable * _Nullable)error { + error:(__autoreleasing NSError * _Nullable * _Nullable)error { __block BOOL success = NO; __block NSError* exceptionError = nil; [RollbarTryCatch try:^(void) { + + tryBlock(); + success = YES; + } + catch:^(NSException *exception) { + + exceptionError = [self convertException:exception]; + + if (nil != self->logger) { - tryBlock(); - success = YES; - } - catch:^(NSException *exception) { - - exceptionError = [self convertException:exception]; - - if (nil != self->logger) { - - [self->logger log:RollbarLevel_Critical - exception:exception - data:nil - context:RollbarExceptionGuard.className - ]; - - [self->logger log:RollbarLevel_Critical - error:exceptionError - data:nil - context:RollbarExceptionGuard.className - ]; - } - - success = NO; - } - finally:^{ + [self->logger log:RollbarLevel_Critical + exception:exception + data:nil + context:RollbarExceptionGuard.className + ]; + [self->logger log:RollbarLevel_Critical + error:exceptionError + data:nil + context:RollbarExceptionGuard.className + ]; } + + success = NO; + } + finally:^{ + + } ]; *error = exceptionError;