【问题标题】:Blazor does not throw a not implemented ExceptionBlazor 不会抛出未实现的异常
【发布时间】:2021-04-15 11:54:58
【问题描述】:

我有这个简单的事件处理程序:

public void RowClicked(TableRowClickEventArgs<Prods> p)
{
    throw new NotImplementedException();            
}

从这个组件中调用:

<MudTable Items="@Products" OnRowClick="@RowClicked" >
</MudTable>

问题是blazor在触发方法时没有抛出任何东西,这种行为正常吗?

【问题讨论】:

  • 您应该会在控制台日志中看到异常消息。

标签: blazor blazor-webassembly


【解决方案1】:

回答您的问题“这种行为正常吗?”。不。(我已经直接说明了这一点,正如昨天一些评论者所说(错误地)发布的内容并没有直接回答问题,因此将其标记下来!!!)。

这是一个非常简单的 razor 标记页面,用于抛出错误并向您展示什么是正常的:

@page "/exceptionpage"

<div class="m-3 p-3">
    <button class="btn btn-danger ml-2" @onclick="() => ThrowException()">Throw Exception</button>
</div>

@code {
    void ThrowException()
        => throw new NotImplementedException();
}

当它在调试中以服务器模式运行时会引发以下控制台输出

The method or operation is not implemented.

'iisexpress.exe' (CoreCLR: clrhost): Loaded 'C:\Program Files\dotnet\shared\Microsoft.NETCore.App\5.0.5\System.Diagnostics.StackTrace.dll'. Skipped loading symbols. Module is optimized and the debugger option 'Just My Code' is enabled.
'iisexpress.exe' (CoreCLR: clrhost): Loaded 'C:\Program Files\dotnet\shared\Microsoft.NETCore.App\5.0.5\System.Reflection.Metadata.dll'. Skipped loading symbols. Module is optimized and the debugger option 'Just My Code' is enabled.
'iisexpress.exe' (CoreCLR: clrhost): Loaded 'C:\Program Files\dotnet\shared\Microsoft.NETCore.App\5.0.5\System.Collections.Immutable.dll'. Skipped loading symbols. Module is optimized and the debugger option 'Just My Code' is enabled.
'iisexpress.exe' (CoreCLR: clrhost): Loaded 'C:\Program Files\dotnet\shared\Microsoft.NETCore.App\5.0.5\System.IO.MemoryMappedFiles.dll'. Skipped loading symbols. Module is optimized and the debugger option 'Just My Code' is enabled.
Microsoft.AspNetCore.Components.Server.Circuits.RemoteRenderer: Warning: Unhandled exception rendering component: The method or operation is not implemented.

System.NotImplementedException: The method or operation is not implemented.
   at Blazor.Starter.Pages.Index.ThrowException() in D:\Shaun\source\repos\Blazor.Starter\Blazor.Starter\Pages\Index.razor:line 61
   at Blazor.Starter.Pages.Index.<BuildRenderTree>b__0_4() in D:\Shaun\source\repos\Blazor.Starter\Blazor.Starter\Pages\Index.razor:line 18
   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.RenderTree.Renderer.DispatchEventAsync(UInt64 eventHandlerId, EventFieldInfo fieldInfo, EventArgs eventArgs)
Microsoft.AspNetCore.Components.Server.Circuits.CircuitHost: Error: Unhandled exception in circuit 'oiyAzPmWxjSN4vTZ-FvyxNu299jz_TxRMituQ8soZC0'.

System.NotImplementedException: The method or operation is not implemented.
   at Blazor.Starter.Pages.Index.ThrowException() in D:\Shaun\source\repos\Blazor.Starter\Blazor.Starter\Pages\Index.razor:line 61
   at Blazor.Starter.Pages.Index.<BuildRenderTree>b__0_4() in D:\Shaun\source\repos\Blazor.Starter\Blazor.Starter\Pages\Index.razor:line 18
   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.RenderTree.Renderer.DispatchEventAsync(UInt64 eventHandlerId, EventFieldInfo fieldInfo, EventArgs eventArgs)

【讨论】:

    【解决方案2】:

    不,这不正常。我根本不相信您的方法正在被调用,即事件正在触发。

    【讨论】:

      猜你喜欢
      • 2016-06-21
      • 2013-03-14
      • 1970-01-01
      • 2015-06-03
      • 2013-12-21
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多