请就以下问题向我提供任何合适的解决方案,
当 blazor 应用程序抛出任何异常时,整个应用程序都会关闭并且没有链接正在工作,直到我可以再次通过工作室运行应用程序。
这个问题怎么办?
谢谢和最好的问候
已编辑
(为了提供所要求的信息)
重现步骤:
创建一个 blazorserverside 应用程序:
修改 IncrementCount
在Counter.razor
:
void IncrementCount()
{
currentCount += 1;
_ = 0 / (5-currentCount); // <-- force error when currentCount is 5.
}
按下
Click Me
按钮 5 次以引发错误。尝试导航到其他应用程序页面(主页、获取数据)没有任何反应,因为它在客户端上静默失败。
附加信息
配置Startup.cs
错误时:
app.UseExceptionHandler("/errors");
堆栈跟踪错误:
Unhandled exception rendering component: Attempted to divide by zero.
System.DivideByZeroException: Attempted to divide by zero.
at blaex.Pages.Counter.IncrementCount() in /home/dani/tmp/blaex/Pages/Counter.razor:line 27
at Microsoft.AspNetCore.Components.EventCallbackWorkItem.InvokeAsync[T](MulticastDelegate delegate, T arg)
at Microsoft.AspNetCore.Components.ComponentBase.Microsoft.AspNetCore.Components.IHandleEvent.HandleEventAsync(EventCallbackWorkItem callback, Object arg)
at Microsoft.AspNetCore.Components.Rendering.Renderer.DispatchEventAsync(Int32 eventHandlerId, UIEventArgs eventArgs)