- r - 以节省内存的方式增长 data.frame
- ruby-on-rails - ruby/ruby on rails 内存泄漏检测
- android - 无法解析导入android.support.v7.app
- UNIX 域套接字与共享内存(映射文件)
我想知道是否有包含所有异常类型的列表。我知道一些异常,但我并不了解所有异常。有时我抛出一个异常,然后我想,也许 .NET 已经有一个异常了。
例如,现在我需要一个表明进程不存在(如文件)的异常。
因此我的问题是:有人知道如何找到所有异常(exception)的列表吗?我没找到。
最佳答案
首先你必须了解什么是异常以及如何处理它。有一些资源可以帮助您理解这个主题。
“选择正确的异常类型来抛出”,作者:Krzysztof Cwalina。 Link
“如何设计异常层次结构”,作者 Krzysztof Cwalina。 Link
Chris Brumme 的异常模式。 Link
可能有帮助:
CLR 团队博客的“为什么捕获(异常)/空捕获不好”。 Link
“编写可靠的异常处理代码”,作者 Bill Wagner。 http://visualstudiomagazine.com/articles/2007/06/01/write-robust-exceptionhandling-code.aspx
“C#:我们是否需要在 C# 中检查异常”Link
还有 Jeffrey Richter 在他的书 CLR via C# build exception hierarchy(p.430,第 19 章)中,最近他编写了一个程序来显示最终派生自 System.Exception 的所有类:
using System;
using System.Text;
using System.Reflection;
using System.Collections.Generic;
public static class Program
{
public static void Main()
{
// Explicitly load the assemblies that we want to reflect over
LoadAssemblies();
// Initialize our counters and our exception type list
Int32 totalPublicTypes = 0, totalExceptionTypes = 0;
List<String> exceptionTree = new List<String>();
// Iterate through all assemblies loaded in this AppDomain
foreach (Assembly a in AppDomain.CurrentDomain.GetAssemblies())
{
// Iterate through all types defined in this assembly
foreach (Type t in a.GetExportedTypes())
{
totalPublicTypes++;
// Ignore type if not a public class
if (!t.IsClass || !t.IsPublic) continue;
// Build a string of the type's derivation hierarchy
StringBuilder typeHierarchy = new StringBuilder(t.FullName, 5000);
// Assume that the type is not an Exception-derived type
Boolean derivedFromException = false;
// See if System.Exception is a base type of this type
Type baseType = t.BaseType;
while ((baseType != null) && !derivedFromException)
{
// Append the base type to the end of the string
typeHierarchy.Append("-" + baseType);
derivedFromException = (baseType == typeof(System.Exception));
baseType = baseType.BaseType;
}
// No more bases and not Exception-derived, try next type
if (!derivedFromException) continue;
// We found an Exception-derived type
totalExceptionTypes++;
// For this Exception-derived type,
// reverse the order of the types in the hierarchy
String[] h = typeHierarchy.ToString().Split('-');
Array.Reverse(h);
// Build a new string with the hierarchy in order
// from Exception -> Exception-derived type
// Add the string to the list of Exception types
exceptionTree.Add(String.Join("-", h, 1, h.Length - 1));
}
}
// Sort the Exception types together in order of their hierarchy
exceptionTree.Sort();
// Display the Exception tree
foreach (String s in exceptionTree)
{
// For this Exception type, split its base types apart
string[] x = s.Split('-');
// Indent based on the number of base types
// and then show the most-derived type
Console.WriteLine(new String(' ', 3 * x.Length) + x[x.Length - 1]);
}
// Show final status of the types considered
Console.WriteLine("\n---> of {0} types, {1} are " +
"derived from System.Exception.",
totalPublicTypes, totalExceptionTypes);
}
private static void LoadAssemblies()
{
String[] assemblies = {
"System, PublicKeyToken={0}",
"System.Data, PublicKeyToken={0}",
"System.Design, PublicKeyToken={1}",
"System.DirectoryServices, PublicKeyToken={1}",
"System.Drawing, PublicKeyToken={1}",
"System.Drawing.Design, PublicKeyToken={1}",
"System.Management, PublicKeyToken={1}",
"System.Messaging, PublicKeyToken={1}",
"System.Runtime.Remoting, PublicKeyToken={0}",
"System.Security, PublicKeyToken={1}",
"System.ServiceProcess, PublicKeyToken={1}",
"System.Web, PublicKeyToken={1}",
"System.Web.RegularExpressions, PublicKeyToken={1}",
"System.Web.Services, PublicKeyToken={1}",
"System.Windows.Forms, PublicKeyToken={0}",
"System.Xml, PublicKeyToken={0}",
};
String EcmaPublicKeyToken = "b77a5c561934e089";
String MSPublicKeyToken = "b03f5f7f11d50a3a";
// Get the version of the assembly containing System.Object
// We'll assume the same version for all the other assemblies
Version version =
typeof(System.Object).Assembly.GetName().Version;
// Explicitly load the assemblies that we want to reflect over
foreach (String a in assemblies)
{
String Assemblyldentity =
String.Format(a, EcmaPublicKeyToken, MSPublicKeyToken) +
", Culture=neutral, Version=" + version;
Assembly.Load(AssemblyIdentity);
}
}
}
关于C# 是否有异常概述?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/2085460/
**设计模式(Design pattern)**是一套被反复使用的、多数人知晓的、经过分类编目的、代码设计经验的总结。使用设计模式是为了重用代码、让代码更容易被他人理解、保证代码可靠性。项目中合理地运
系统定义 系统定位 HarmonyOS是一款“面向未来”、面向全场景(移动办公、运动健康、社交通信、媒体娱乐等)的分布式操作系统。在传统的单设备系统能力的基础上,HarmonyOS提出了基于同一套系统
我有 dplyr::recode一些因素,我正在寻找一种干净的方法来制作 LaTeX 表,其中比较新旧类别,即级别。 这是使用 cyl 的问题的说明来自`mtcars。首先是一些包, # instal
简介 Blazor 是一种 .NET 前端 Web 框架,同时支持服务器端呈现和客户端交互性。 使用 C# 语言创建丰富的交互式 UI 共享前后端应用逻辑 可以生成
thinkPHP的F方法只能用于缓存简单数据类型,不支持有效期和缓存对象。S()缓存方法支持有效期,又称动态缓存方法,使用示例如下: 复制代码 代码如下: // 使用d
在.NET开发中,我们经常会在bin目录下面看到这些类型的文件: .pdb、.xsd、.vshost.exe、.exe、.exe.config、.vshost.exe.config 项目发布的时
VMware Cloud Foundation(简称 VCF)是 VMware 打造的一套用于 Software Defined Data Center(SDDC)软件定义数据中心的全栈云平台解决方案
HBase 概述 HBase是[Hadoop][]的生态系统,是建立在Hadoop文件系统(HDFS)之上的分布式、面向列的数据库,通过利用Hadoop的文件系统提供容错能力。如果你需要进行实时读写
JUnit – 概述 所谓单元测试是测试应用程序的功能是否能够按需要正常运行,并且确保是在开发人员的水平上,单元测试生成图片。单元测试是一个对单一实体(类或方法)的测试。单元测试是每个软件公司提高产
Maven – 概述 Maven 是什么? Maven 是一个项目管理和整合工具。Maven 为开发者提供了一套完整的构建生命周期框架。开发团队几乎不用花多少时间就能够自动完成工程的基础构建配置,
概述 特性说明 下面是一些 Gradle 特性的列表。 基于声明的构建和基于约定的构建 Gradle 的核心在于基于 Groovy 的丰富而可扩展的域描述语言(DSL)。 Groovy 通过声
我正在创建 TopDesk 的概述。我想问你们中的一些人,完成这项工作的最佳方法是什么。 最后,应用程序将设置在大屏幕上,以便每个人都可以看到我们有多少个 topdesk 调用。 我想到了以下选项:
我正在使用 SpriteKit 的 框架制作游戏。我如何使用 SKLabelNodes 制作轮廓文本?似乎没有这样做的内置功能。如果在 SpriteKit 中没有办法做到这一点,我还有什么其他方法可以
函数式编程中非常通用的函数是什么样的? 有人说“我们没有对象,但我们有高阶函数”。高阶函数会取代对象吗? 在编写面向对象的应用程序时,我多次尝试从更一般的想法转向更详细的想法。如果我尝试在函数式编程中
序言 构建这个概念是和应用程序包及资源等相关的,它的特点是使用脚本控制一系列的任务的处理,以减少人力操作带来的成本和操作失误风险。 在UE的概念里,构建往往是和打包相关的(如编译、coo
1. 概述 webpack作用:前端项目构建工具 - 打包工具 - 可解决下面的开发问题 Web开发面对的问题文件依赖关系复杂静态资源请求效率低模块化支持不好浏览器对高级JS语法兼容程度低 不用web
我刚刚收到关于 Compound Literals 错误的评论,并且在此过程中偶然发现了可变长度数组。显然我一直生活在一 block 岩石下。为了更好地理解 C99 中的主要新特性,我应该阅读哪些内容
关闭。这个问题不满足Stack Overflow guidelines .它目前不接受答案。 想改善这个问题吗?更新问题,使其成为 on-topic对于堆栈溢出。 8年前关闭。 Improve thi
Java UI 插件提供接口(interface) ISharedImages 访问可以在自己的插件中使用的标准图像。 例如 Image image = PlatformUI.getWorkbench
我正在尝试将其设置为角色在图 block 中的位置,当他们向上或向下移动时它会移动到下一个图 block ,但我不确定该怎么做。现在,我设置了角色移动像素的位置,但我希望它移动 1 个方格。 现在的代
我是一名优秀的程序员,十分优秀!