实例方法
breakpoint
breakpointOnError()
在收到故障时引发调试器信号。
声明
func breakpointOnError() -> Publishers.Breakpoint<Self>
返回值
发布者在收到失败时引发调试器信号。
详述
当上游发布者因错误而失败时,该发布者会引发 SIGTRAP
信号,从而停止调试器中的进程。否则,此发布者按原样传递值和完成。
在此示例中,PassthroughSubject
发布字符串,但其下游 Publisher/tryMap(_:)
运算符引发错误。这会将错误作为 Subscribers/Completion/failure(_:)
发送到下游。 Publisher/breakpointOnError()
运算符接收此完成并在调试器中停止应用程序。
struct CustomError : Error {}
let publisher = PassthroughSubject<String?, Error>()
cancellable = publisher
.tryMap { stringValue in
throw CustomError()
}
.breakpointOnError()
.sink(
receiveCompletion: { completion in print("Completion: \(String(describing: completion))") },
receiveValue: { aValue in print("Result: \(String(describing: aValue))") }
)
publisher.send("TEST DATA")
// Prints: "error: Execution was interrupted, reason: signal SIGTRAP."
// Depending on your specific environment, the console messages may
// also include stack trace information, which is not shown here.
可用版本
iOS 13.0+, iPadOS 13.0+, macOS 10.15+, Mac Catalyst 13.0+, tvOS 13.0+, watchOS 6.0+
相关用法
- Swift Optional.Publisher breakpoint(receiveSubscription:receiveOutput:receiveCompletion:)用法及代码示例
- Swift Optional.Publisher reduce(_:_:)用法及代码示例
- Swift Optional.Publisher tryDrop(while:)用法及代码示例
- Swift Optional.Publisher debounce(for:scheduler:options:)用法及代码示例
- Swift Optional.Publisher mapError(_:)用法及代码示例
- Swift Optional.Publisher catch(_:)用法及代码示例
- Swift Optional.Publisher tryAllSatisfy(_:)用法及代码示例
- Swift Optional.Publisher zip(_:_:_:)用法及代码示例
- Swift Optional.Publisher sink(receiveValue:)用法及代码示例
- Swift Optional.Publisher scan(_:_:)用法及代码示例
- Swift Optional.Publisher throttle(for:scheduler:latest:)用法及代码示例
- Swift Optional.Publisher assertNoFailure(_:file:line:)用法及代码示例
- Swift Optional.Publisher collect(_:)用法及代码示例
- Swift Optional.Publisher combineLatest(_:_:_:_:)用法及代码示例
- Swift Optional.Publisher share()用法及代码示例
- Swift Optional.Publisher merge(with:_:_:)用法及代码示例
- Swift Optional.Publisher map(_:_:)用法及代码示例
- Swift Optional.Publisher assign(to:on:)用法及代码示例
- Swift Optional.Publisher zip(_:_:_:_:)用法及代码示例
- Swift Optional.Publisher output(in:)用法及代码示例
- Swift Optional.Publisher tryReduce(_:_:)用法及代码示例
- Swift Optional.Publisher map(_:_:_:)用法及代码示例
- Swift Optional.Publisher prepend(_:)用法及代码示例
- Swift Optional.Publisher removeDuplicates()用法及代码示例
- Swift Optional.Publisher merge(with:_:_:_:_:_:_:)用法及代码示例
注:本文由纯净天空筛选整理自apple.com大神的英文原创作品 Optional.Publisher breakpointOnError()。非经特殊声明,原始代码版权归原作者所有,本译文未经允许或授权,请勿转载或复制。