Skip to content

Commit 77a5590

Browse files
committed
doc: 更新全局异常示例
1 parent 8d3e9e5 commit 77a5590

File tree

7 files changed

+52
-4
lines changed

7 files changed

+52
-4
lines changed

src/BootstrapBlazor.Server/Components/Layout/MainLayout.razor

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,9 @@
1515

1616
<section class="main">
1717
<Wwads />
18-
@Body
18+
<ErrorLogger>
19+
@Body
20+
</ErrorLogger>
1921
</section>
2022

2123
<DialButton DialMode="DialMode.Radial" Icon="fa-solid fa-gear" Radius="100" Placement="Placement.BottomEnd" class="bb-dial-gear">
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
@page "/error-page"
2+
3+
<h3>ErrorPage</h3>
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
// Licensed to the .NET Foundation under one or more agreements.
2+
// The .NET Foundation licenses this file to you under the Apache 2.0 License
3+
// See the LICENSE file in the project root for more information.
4+
// Maintainer: Argo Zhang([email protected]) Website: https://www.blazor.zone
5+
6+
namespace BootstrapBlazor.Server.Components.Pages;
7+
8+
/// <summary>
9+
/// ErrorPage 组件用于测试全局异常处理功能
10+
/// </summary>
11+
public partial class ErrorPage
12+
{
13+
/// <summary>
14+
/// <inheritdoc/>
15+
/// </summary>
16+
protected override void OnInitialized()
17+
{
18+
base.OnInitialized();
19+
20+
var a = 1;
21+
var b = 0;
22+
23+
// 这里会抛出异常
24+
var c = 1 / b;
25+
}
26+
}

src/BootstrapBlazor.Server/Components/Samples/GlobalException.razor

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -72,4 +72,8 @@
7272
<Button Icon="fa-solid fa-font-awesome" Text="@Localizer["DialogText"]" OnClick="OnShowDialog" />
7373
</DemoBlock>
7474

75+
<DemoBlock Title="@Localizer["PageErrorTitle"]" Introduction="@Localizer["PageErrorIntro"]" Name="Page">
76+
<Button Icon="fa-solid fa-font-awesome" Text="@Localizer["ButtonText"]" OnClick="OnGotoPage" />
77+
</DemoBlock>
78+
7579
<AttributeTable Items="@GetAttributes()" />

src/BootstrapBlazor.Server/Components/Samples/GlobalException.razor.cs

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,10 @@ namespace BootstrapBlazor.Server.Components.Samples;
1010
/// </summary>
1111
public partial class GlobalException
1212
{
13+
[Inject]
14+
[NotNull]
15+
private NavigationManager? NavigationManager { get; set; }
16+
1317
[Inject]
1418
[NotNull]
1519
private SwalService? SwalService { get; set; }
@@ -19,7 +23,6 @@ public partial class GlobalException
1923

2024
private static void OnClick()
2125
{
22-
// NET6.0 采用 ErrorLogger 统一处理
2326
var a = 0;
2427
_ = 1 / a;
2528
}
@@ -39,6 +42,12 @@ private Task OnShowDialog() => DialogService.Show(new DialogOption()
3942
Component = BootstrapDynamicComponent.CreateComponent<MockError>()
4043
});
4144

45+
private Task OnGotoPage()
46+
{
47+
NavigationManager.NavigateTo("/error-page");
48+
return Task.CompletedTask;
49+
}
50+
4251
/// <summary>
4352
/// 获得属性方法
4453
/// </summary>

src/BootstrapBlazor.Server/Locales/en-US.json

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1725,7 +1725,9 @@
17251725
"Block2Intro": "Set custom exception handling logic by setting <code>OnErrorHandleAsync</code> callback method",
17261726
"DialogTitle": "In Dialog",
17271727
"DialogIntro": "Click the button to pop up a pop-up window. The button in the pop-up window triggers an exception and the error is displayed in the pop-up window",
1728-
"DialogText": "Popup"
1728+
"DialogText": "Popup",
1729+
"PageErrorTitle": "Page",
1730+
"PageErrorIntro": "Click the button to navigate to the page where the error occurred during the page life cycle. The error is displayed on the current page and does not affect the menu and the overall page layout."
17291731
},
17301732
"BootstrapBlazor.Server.Components.Pages.GlobalOption": {
17311733
"Title": "Global exception",

src/BootstrapBlazor.Server/Locales/zh-CN.json

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1725,7 +1725,9 @@
17251725
"Block2Intro": "通过设置 <code>OnErrorHandleAsync</code> 回调方法,设置自定义异常处理逻辑",
17261726
"DialogTitle": "弹窗中异常捕获",
17271727
"DialogIntro": "点击按钮弹出弹窗,弹窗内按钮触发异常,错误显示在弹窗内",
1728-
"DialogText": "弹窗"
1728+
"DialogText": "弹窗",
1729+
"PageErrorTitle": "页面异常捕获",
1730+
"PageErrorIntro": "点击按钮导航到页面生命周期内出错的页面,错误显示在当前页面,不影响菜单以及整体页面布局"
17291731
},
17301732
"BootstrapBlazor.Server.Components.Pages.GlobalOption": {
17311733
"Title": "全局配置",

0 commit comments

Comments
 (0)