簡體   English   中英

用C#代碼記錄異常

[英]Documenting an exception in C# code

我在mscorlib.xml (從摘要生成的XML文件)中注意到它包含:

<member name="M:System.Console.ReadKey">
  <summary>Obtains the next character or function key pressed by the user. The pressed key is displayed in the console window.</summary>
  <returns>A <see cref="T:System.ConsoleKeyInfo" /> object that describes the <see cref="T:System.ConsoleKey" /> constant and Unicode character, if any, that correspond to the pressed console key. The <see cref="T:System.ConsoleKeyInfo" /> object also describes, in a bitwise combination of <see cref="T:System.ConsoleModifiers" /> values, whether one or more SHIFT, ALT, or CTRL modifier keys was pressed simultaneously with the console key.</returns>
  <exception cref="T:System.InvalidOperationException">The <see cref="P:System.Console.In" /> property is redirected from some stream other than the console.</exception>
  <filterpriority>1</filterpriority>
</member>

從該示例中,我特別感興趣:

<exception cref="T:System.InvalidOperationException">The <see cref="P:System.Console.In" /> property is redirected from some stream other than the console.</exception>

您如何在代碼中記錄異常,以使它們最終出現在XML中?

這是一個例子:

/// <exception cref="ArgumentException">
/// Thrown when the <typeparamref name="TConcrete"/> is a type
/// that can not be created by the container.
/// </exception>

換句話說,與您在問題中已經顯示的代碼段完全一樣。

您可以在源代碼的XML注釋中使用<exception>標記添加異常文檔。 例如:

///<summary>Summary of method/property/etc</summary>
///<returns>Returns a value</returns>
///<exception>Throws an exception</exception>

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM