Blazor笔记-Error handling
更新记录#
注意:非教程。纯笔记,日常查询用的。需要教程的小伙伴找几本书看看即可哈哈,有Vue基础的话非常快,概念都是通的。非工作需要不建议深入学习Blazor,深入Vue吧,用的多,哈哈。完整目录地址:https://www.cnblogs.com/cqpanda/p/17596348.html
点击查看
2024年3月7日 发布。
2023年8月1日 迁移笔记到博客。
Types of errors#
Server Faults: These types of errors are handled by the host, and Blazor Server has no control over them. They are usually caused by issues such as network connectivity, server overload, or hardware failure.
HTTP Errors: These types of errors do not directly come from your Blazor Server website, but from the third-party API side. However, you can catch these errors.
Client-Side Errors: These types of errors are usually caused by components, either by C# code or JavaScript. Blazor allows you to catch these errors and handle them accordingly. They are typically related to issues such as invalid user input, unexpected user behavior, or client-side script errors.
全局异常处理#
app.UseExceptionHandler("/BlazorSchoolError");
指定错误显示的内容#
Error boundaries#
In .NET 6, we got a very handy component to handle errors called ErrorBoundary
<ErrorBoundary @ref="MyErrorBoundary">
<ChildContent>
<TriggerError/>
</ChildContent>
<ErrorContent>
An error occurred. <button @onclick="_ => MyErrorBoundary?.Recover()">Continue</button>
</ErrorContent>
</ErrorBoundary>
@code {
public ErrorBoundary? MyErrorBoundary { get; set; }
}
实例
<ErrorBoundary>
<ChildContent>
<Index2></Index2>
</ChildContent>
<ErrorContent>
<h1 style="color: red;">错误啊啊啊啊</h1>
</ErrorContent>
</ErrorBoundary>
作者:重庆熊猫
出处:https://www.cnblogs.com/cqpanda/p/17596932.html
版权:本作品采用「不论是否商业使用都不允许转载,否则按3元1字进行收取费用」许可协议进行许可。
本文来自博客园,作者:重庆熊猫,转载请注明原文链接:https://www.cnblogs.com/cqpanda/p/17596932.html
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· 阿里最新开源QwQ-32B,效果媲美deepseek-r1满血版,部署成本又又又降低了!
· 单线程的Redis速度为什么快?
· SQL Server 2025 AI相关能力初探
· AI编程工具终极对决:字节Trae VS Cursor,谁才是开发者新宠?
· 展开说说关于C#中ORM框架的用法!