Skip to content

Commit 7eb1547

Browse files
authored
Update MAUI Exception Handling (#40765)
1 parent a351c43 commit 7eb1547

File tree

3 files changed

+6
-4
lines changed

3 files changed

+6
-4
lines changed

src/Components/README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ The following contains a description of each sub-directory in the `Components` d
2626
- `Server`: Contains the implementation for WASM-specific extension methods and the launch logic for the debugging proxy
2727
- `WebAssembly`: Contains WebAssembly-specific implementations of the renderer, HostBuilder, etc.
2828
- `WebAssembly.Authentication`: Contains the WASM-specific implementations
29+
- `WebView`: Contains the source files to support [Blazor Hybrid](https://github.com/dotnet/maui/tree/main/src/BlazorWebView) within [`dotnet/maui`](https://github.com/dotnet/maui). Changes in this project can be tested with `dotnet/maui` following [this guide](https://github.com/dotnet/maui/wiki/Blazor-Desktop#aspnet-core).
2930

3031
## Development Setup
3132

src/Components/WebView/WebView/src/IpcSender.cs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33

44
using System;
55
using System.Diagnostics.CodeAnalysis;
6+
using System.Runtime.ExceptionServices;
67
using System.Threading.Tasks;
78
using Microsoft.AspNetCore.Components.RenderTree;
89
using Microsoft.JSInterop;
@@ -62,8 +63,12 @@ public void SendByteArray(int id, byte[] data)
6263

6364
public void NotifyUnhandledException(Exception exception)
6465
{
66+
// Send the serialized exception to the WebView for display
6567
var message = IpcCommon.Serialize(IpcCommon.OutgoingMessageType.NotifyUnhandledException, exception.Message, exception.StackTrace);
6668
_dispatcher.InvokeAsync(() => _messageDispatcher(message));
69+
70+
// Also rethrow so the AppDomain's UnhandledException handler gets notified
71+
_dispatcher.InvokeAsync(() => ExceptionDispatchInfo.Capture(exception).Throw());
6772
}
6873

6974
private void DispatchMessageWithErrorHandling(string message)

src/Components/WebView/WebView/src/Services/WebViewRenderer.cs

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
// Licensed to the .NET Foundation under one or more agreements.
22
// The .NET Foundation licenses this file to you under the MIT license.
33

4-
using System.Runtime.ExceptionServices;
54
using System.Text.Json;
65
using Microsoft.AspNetCore.Components.RenderTree;
76
using Microsoft.AspNetCore.Components.Web;
@@ -38,9 +37,6 @@ protected override void HandleException(Exception exception)
3837
{
3938
// Notify the JS code so it can show the in-app UI
4039
_ipcSender.NotifyUnhandledException(exception);
41-
42-
// Also rethrow so the AppDomain's UnhandledException handler gets notified
43-
ExceptionDispatchInfo.Capture(exception).Throw();
4440
}
4541

4642
protected override Task UpdateDisplayAsync(in RenderBatch renderBatch)

0 commit comments

Comments
 (0)