import XCTest

extension RunnerTests {








  func safely<T>(_ tag: String, _ fallback: T, _ block: () -> T) -> T {
    let (result, exceptionMessage) = catchingObjCException(fallback: fallback, block)
    if let exceptionMessage {
      NSLog("AGENT_DEVICE_RUNNER_%@_IGNORED_EXCEPTION=%@", tag, exceptionMessage)
      return fallback
    }
    return result
  }

  func catchingObjCException<T>(
    fallback: T,
    _ block: () -> T
  ) -> (result: T, exceptionMessage: String?) {
    var result = fallback
    let exceptionMessage = RunnerObjCExceptionCatcher.catchException({
      result = block()
    })
    return (result, exceptionMessage)
  }



  func safely<T>(_ tag: String, _ block: () -> T?) -> T? {
    safely(tag, nil, block)
  }
}
