本文整理匯總了C#中System.Exception.InnerException屬性的典型用法代碼示例。如果您正苦於以下問題:C# Exception.InnerException屬性的具體用法?C# Exception.InnerException怎麽用?C# Exception.InnerException使用的例子?那麽, 這裏精選的屬性代碼示例或許可以為您提供幫助。您也可以進一步了解該屬性所在類System.Exception
的用法示例。
在下文中一共展示了Exception.InnerException屬性的1個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的C#代碼示例。
示例1: AppException
//引入命名空間
using System;
public class AppException : Exception
{
public AppException(String message) : base (message)
{}
public AppException(String message, Exception inner) : base(message,inner) {}
}
public class Example
{
public static void Main()
{
Example ex = new Example();
try {
ex.CatchInner();
}
catch(AppException e) {
Console.WriteLine ("In catch block of Main method.");
Console.WriteLine("Caught: {0}", e.Message);
if (e.InnerException != null)
Console.WriteLine("Inner exception: {0}", e.InnerException);
}
}
public void ThrowInner ()
{
throw new AppException("Exception in ThrowInner method.");
}
public void CatchInner()
{
try {
this.ThrowInner();
}
catch (AppException e) {
throw new AppException("Error in CatchInner caused by calling the ThrowInner method.", e);
}
}
}
輸出:
In catch block of Main method. Caught: Error in CatchInner caused by calling the ThrowInner method. Inner exception: AppException: Exception in ThrowInner method. at Example.CatchInner()