{
  "schemaVersion": "0.11.0",
  "canonical": "https://www.pystone.net/notes/csharp-exception-handling/",
  "atlas": "https://www.pystone.net/?node=csharp-exception-handling#knowledge-atlas",
  "markdown": "https://www.pystone.net/notes/csharp-exception-handling.md",
  "context": "https://www.pystone.net/notes/csharp-exception-handling.context.json",
  "knowledgeVersion": "224c990773de.5fa8af6e39fa",
  "build": {
    "siteCommit": "224c990773de166d23a886306577dd90379529ce",
    "notesCommit": "5fa8af6e39fa3891d1b9b4832bfa6c4e0ecaaf0a",
    "builtAt": "1970-01-01T00:00:00.000Z",
    "version": "224c990773de.5fa8af6e39fa"
  },
  "id": "note:csharp-exception-handling",
  "slug": "csharp-exception-handling",
  "title": "Exception",
  "type": "note",
  "visibility": "public",
  "idStability": "rename-stable",
  "author": {
    "name": "Perrin Yong",
    "profile": "https://www.pystone.net/profile/"
  },
  "publisher": {
    "name": "Perrin Yong",
    "profile": "https://www.pystone.net/profile/"
  },
  "aliases": [],
  "summary": "Exception",
  "contentRole": "unspecified",
  "isMoc": false,
  "mocRecognition": "none",
  "generated": false,
  "attribution": "unspecified",
  "domain": "10-计算机、信息技术与工程",
  "tags": [],
  "mocs": [],
  "contentHash": "6803cb00e5347a3252bd5cac0546e5acfd37718c9f5e1a480b418d34bf424d63",
  "assets": [],
  "headings": [
    {
      "depth": 1,
      "text": "Exception",
      "anchor": "exception",
      "citation": "https://www.pystone.net/notes/csharp-exception-handling/#exception"
    },
    {
      "depth": 2,
      "text": "throw的异常路径问题",
      "anchor": "throw的异常路径问题",
      "citation": "https://www.pystone.net/notes/csharp-exception-handling/#throw%E7%9A%84%E5%BC%82%E5%B8%B8%E8%B7%AF%E5%BE%84%E9%97%AE%E9%A2%98"
    },
    {
      "depth": 2,
      "text": "InnerException",
      "anchor": "innerexception",
      "citation": "https://www.pystone.net/notes/csharp-exception-handling/#innerexception"
    }
  ],
  "claims": [],
  "outgoing": [],
  "incoming": [
    {
      "id": "note:programming-languages-and-runtimes",
      "title": "编程语言与运行时",
      "url": "https://www.pystone.net/notes/programming-languages-and-runtimes/",
      "atlas": "https://www.pystone.net/?node=programming-languages-and-runtimes#knowledge-atlas",
      "label": "编程语言与运行时",
      "origin": "explicit",
      "humanReviewed": true,
      "context": ".NET与CSharp中的“Exception”导航项",
      "citation": "https://www.pystone.net/notes/programming-languages-and-runtimes/#net%E4%B8%8Ecsharp"
    }
  ],
  "contentMarkdown": "# Exception\n\n> 创建时间：2020/6/1 11:34\n\n## throw的异常路径问题\n\n参考:<https://blog.csdn.net/wangtian2014/article/details/51593789>\n\n  1. 例1throw的时候使用了参数ex，虽然会抛出同样的异常，但是异常的堆栈信息缺在throw的时候被改变了，我们在接下来的try块中无法获取异常的原始信息。\n\n  2. 例2没有参数，这个无参的throw可以看做为rethrow（即继续抛出），他会抛出之前捕获到的所有异常。\n\n  3. 例3则完全是一个新的异常，class1中抛出的异常被当做内部异常，存放在inner exception中\n\n```csharp\nclass MyClass&lt;T, U&gt;\n    where T : class\n    where U : struct\n{ }\n\n```\n```csharp\nclass MyClass&lt;T, U&gt;\n    where T : class\n    where U : struct\n{ }\n\n```\n```csharp\nclass MyClass&lt;T, U&gt;\n    where T : class\n    where U : struct\n{ }\n\n```\n\n## InnerException\n\n当 Y上一个异常的直接结果引发 X 异常时，X 的 InnerException 属性应包含对 Y的引用。\n你可以创建一个新的异常来捕获更早的异常。 处理第二个异常的代码可以利用以前异常中的其他信息来更正确地处理错误。\n\n```csharp\nclass MyClass&lt;T, U&gt;\n    where T : class\n    where U : struct\n{ }\n\n```\n\n新的异常可以添加新的信息，新异常的堆栈信息包含InnerException的堆栈信息\n"
}
