gpt4 book ai didi

error-handling - 有没有办法全局捕获 Blazor 单页应用程序中所有未处理的错误?

转载 作者:行者123 更新时间:2023-12-01 23:27:06 27 4
gpt4 key购买 nike

我希望能够在构建 Blazor 单页应用程序的一个地方捕获所有未处理的异常。
就像在 WPF 应用程序中使用“Current.DispatcherUnhandledException”一样。

这个问题完全是关于客户端(webassembly)异常处理的。
我正在使用 Blazor 版本 3.0.0-preview8.19405.7

我一直在寻找解决方案,但似乎它不存在。在 Microsoft 的文档 ( https://docs.microsoft.com/en-us/aspnet/core/blazor/handle-errors?view=aspnetcore-3.0 ) 上,有一个可能发生错误的地方列表,以及如何处理每个错误的演练。
它相信必须有一种更防弹的方法来捕获所有。

最佳答案

目前没有中央位置来捕获和处理客户端异常。

这是史蒂夫桑德森的一段话:

So overall, each component must deal with handling its own errors. If you want, you could make your own ErrorHandlingComponentBase to inherit from, and put a try/catch around all the lifecycle methods, and have your own logic for displaying an "oh dear sorry I died" UI on that component if anything went wrong. But it's not a feature of the framework today.



我希望这会在 future 改变,我相信应该支持框架。

关于error-handling - 有没有办法全局捕获 Blazor 单页应用程序中所有未处理的错误?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/57539330/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com