Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Move code samples and BWA handle errors 8.0 #29918

Merged
merged 5 commits into from
Jul 26, 2023
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Updates
guardrex committed Jul 26, 2023

Verified

This commit was created on GitHub.com and signed with GitHub’s verified signature.
commit bc9c558c9bf93b09e8bb7f9bc330fa8cf0fffd7f
68 changes: 37 additions & 31 deletions aspnetcore/blazor/fundamentals/handle-errors.md
Original file line number Diff line number Diff line change
@@ -21,20 +21,34 @@ When a Blazor app isn't functioning properly during development, receiving detai
* During development, the bar directs you to the browser console, where you can see the exception.
* In production, the bar notifies the user that an error has occurred and recommends refreshing the browser.

The UI for this error handling experience is part of the [Blazor project templates](xref:blazor/project-structure):

```html
<div id="blazor-error-ui">
An unhandled error has occurred.
<a href="" class="reload">Reload</a>
<a class="dismiss">🗙</a>
</div>
```
The UI for this error handling experience is part of the [Blazor project templates](xref:blazor/project-structure).

:::moniker range=">= aspnetcore-8.0"

In a Blazor Web App, customize the experience in the `App.razor` file. Because the [Environment Tag Helper](xref:mvc/views/tag-helpers/builtin-th/environment-tag-helper) (for example, `<environment include="Production">...</environment>`) isn't supported in Razor components, the following example injects <xref:Microsoft.Extensions.Hosting.IHostEnvironment> to configure error messages for different environments.

:::moniker-end

:::moniker range=">= aspnetcore-7.0 < aspnetcore-8.0"

In a Blazor Server app, customize the experience in the `Pages/_Host.cshtml` file. The following example uses the [Environment Tag Helper](xref:mvc/views/tag-helpers/builtin-th/environment-tag-helper) to configure error messages for different environments.

:::moniker-end

:::moniker range=">= aspnetcore-6.0 < aspnetcore-7.0"

In a Blazor Server app, customize the experience in the `Pages/_Layout.cshtml` file. The following example uses the [Environment Tag Helper](xref:mvc/views/tag-helpers/builtin-th/environment-tag-helper) to configure error messages for different environments.

:::moniker-end

:::moniker range="< aspnetcore-6.0"

In a Blazor Server app, customize the experience in the `Pages/_Host.cshtml` file. The following example uses the [Environment Tag Helper](xref:mvc/views/tag-helpers/builtin-th/environment-tag-helper) to configure error messages for different environments.

:::moniker-end

:::moniker range=">= aspnetcore-8.0"

At the top of the `App` component file (`App.razor`):

```razor
@@ -58,27 +72,9 @@ Create or modify the Blazor error UI markup:
</div>
```

In a Blazor WebAssembly app, customize the experience in the `wwwroot/index.html` file. The following example uses the [Environment Tag Helper](xref:mvc/views/tag-helpers/builtin-th/environment-tag-helper) to configure error messages for different environments:

:::moniker-end

:::moniker range=">= aspnetcore-7.0 < aspnetcore-8.0"

In a Blazor Server app, customize the experience in the `Pages/_Host.cshtml` file. In a Blazor WebAssembly app, customize the experience in the `wwwroot/index.html` file. The following example uses the [Environment Tag Helper](xref:mvc/views/tag-helpers/builtin-th/environment-tag-helper) to configure error messages for different environments:

:::moniker-end

:::moniker range=">= aspnetcore-6.0 < aspnetcore-7.0"

In a Blazor Server app, customize the experience in the `Pages/_Layout.cshtml` file. In a Blazor WebAssembly app, customize the experience in the `wwwroot/index.html` file. The following example uses the [Environment Tag Helper](xref:mvc/views/tag-helpers/builtin-th/environment-tag-helper) to configure error messages for different environments:

:::moniker-end

:::moniker range="< aspnetcore-6.0"

In a Blazor Server app, customize the experience in the `Pages/_Host.cshtml` file. In a Blazor WebAssembly app, customize the experience in the `wwwroot/index.html` file. The following example uses the [Environment Tag Helper](xref:mvc/views/tag-helpers/builtin-th/environment-tag-helper) to configure error messages for different environments:
:::moniker range="< aspnetcore-8.0"

:::moniker-end
Create or modify the Blazor error UI markup:

```cshtml
<div id="blazor-error-ui">
@@ -93,6 +89,18 @@ In a Blazor Server app, customize the experience in the `Pages/_Host.cshtml` fil
</div>
```

:::moniker-end

In a Blazor WebAssembly app, customize the experience in the `wwwroot/index.html` file:

```html
<div id="blazor-error-ui">
An unhandled error has occurred.
<a href="" class="reload">Reload</a>
<a class="dismiss">🗙</a>
</div>
```

:::moniker range=">= aspnetcore-8.0"

The `blazor-error-ui` element is normally hidden due to the presence of the `display: none` style of the `blazor-error-ui` CSS class in the app's stylesheet (`wwwroot/css/app.css`). When an error occurs, the framework applies `display: block` to the element.
@@ -105,8 +113,6 @@ The `blazor-error-ui` element is normally hidden due to the presence of the `dis

:::moniker-end



:::moniker range=">= aspnetcore-8.0"

## Handle caught exceptions outside of a Razor component's lifecycle