当前位置: 首页>>代码示例>>C#>>正文


C# StackFrame构造函数代码示例

本文整理汇总了C#中System.Diagnostics.StackFrame.StackFrame构造函数的典型用法代码示例。如果您正苦于以下问题:C# StackFrame构造函数的具体用法?C# StackFrame怎么用?C# StackFrame使用的例子?那么恭喜您, 这里精选的构造函数代码示例或许可以为您提供帮助。您也可以进一步了解该构造函数所在System.Diagnostics.StackFrame的用法示例。


在下文中一共展示了StackFrame构造函数的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: Main

[STAThread]
static void Main()
 {
     ClassLevel1 mainClass = new ClassLevel1();

     try {
         mainClass.InternalMethod();
     }
     catch (Exception) {
        Console.WriteLine(" Main method exception handler");

        // Display file and line information, if available.
        StackTrace st = new StackTrace(new StackFrame(true));
        Console.WriteLine(" Stack trace for current level: {0}",
            st.ToString());
        Console.WriteLine(" File: {0}", 
           st.GetFrame(0).GetFileName());
        Console.WriteLine(" Line Number: {0}",
            st.GetFrame(0).GetFileLineNumber().ToString());

        Console.WriteLine();
        Console.WriteLine("-------------------------------------------------\n");
     }
 }
开发者ID:.NET开发者,项目名称:System.Diagnostics,代码行数:24,代码来源:StackFrame

示例2: InternalMethod

public void InternalMethod()
{
   try
   {
      ClassLevel2 nestedClass = new ClassLevel2();
      nestedClass.Level2Method();
   }
   catch (Exception e)
   {
      Console.WriteLine(" InternalMethod exception handler");

      // Build a stack trace from one frame, skipping the
      // current frame and using the next frame.  By
      // default, file and line information are not displayed.
      StackTrace st = new StackTrace(new StackFrame(1));
      Console.WriteLine(" Stack trace for next level frame: {0}",
         st.ToString());
      Console.WriteLine(" Stack frame for next level: ");
      Console.WriteLine("   {0}", st.GetFrame(0).ToString());

      Console.WriteLine(" Line Number: {0}",
         st.GetFrame(0).GetFileLineNumber().ToString());

      Console.WriteLine();
      Console.WriteLine("   ... throwing exception to next level ...");
      Console.WriteLine("-------------------------------------------------\n");
      throw e;
   }
}
开发者ID:.NET开发者,项目名称:System.Diagnostics,代码行数:29,代码来源:StackFrame

示例3: Level2Method

public void Level2Method()
{
   try 
   {
      ClassLevel3 nestedClass = new ClassLevel3();
      nestedClass.Level3Method();
   }
   catch (Exception e) 
   {
      Console.WriteLine(" Level2Method exception handler");

      // Display the full call stack at this level.
      StackTrace st1 = new StackTrace(true);
      Console.WriteLine(" Stack trace for this level: {0}",
         st1.ToString());

      // Build a stack trace from one frame, skipping the current
      // frame and using the next frame.
      StackTrace st2 = new StackTrace(new StackFrame(1, true));
      Console.WriteLine(" Stack trace built with next level frame: {0}",
         st2.ToString());

      // Build a stack trace skipping the current frame, and
      // including all the other frames.
      StackTrace st3 = new StackTrace(1, true);
      Console.WriteLine(" Stack trace built from the next level up: {0}",
         st3.ToString());

      Console.WriteLine();
      Console.WriteLine("   ... throwing exception to next level ...");
      Console.WriteLine("-------------------------------------------------\n");
      throw e;
   }
}
开发者ID:.NET开发者,项目名称:System.Diagnostics,代码行数:34,代码来源:StackFrame

示例4: Level3Method

public void Level3Method()
{
   try 
   {
      ClassLevel4 nestedClass = new ClassLevel4();
      nestedClass.Level4Method();
   }
   catch (Exception e) 
   {
      Console.WriteLine(" Level3Method exception handler");

      // Build a stack trace from a dummy stack frame.
      // Explicitly specify the source file name and 
      // line number.
      StackTrace st = new StackTrace(new StackFrame("source.cs", 60));
      Console.WriteLine(" Stack trace with dummy stack frame: {0}", 
                  st.ToString());
      for(int i =0; i< st.FrameCount; i++ )
      {
         // Display the stack frame properties.
         StackFrame sf = st.GetFrame(i);
         Console.WriteLine(" File: {0}", sf.GetFileName());
         Console.WriteLine(" Line Number: {0}", 
            sf.GetFileLineNumber());
         // Note that the column number defaults to zero
         // when not initialized.
         Console.WriteLine(" Column Number: {0}", 
            sf.GetFileColumnNumber());
         if (sf.GetILOffset() != StackFrame.OFFSET_UNKNOWN)
         {
            Console.WriteLine(" Intermediate Language Offset: {0}", 
               sf.GetILOffset());
         }
         if (sf.GetNativeOffset() != StackFrame.OFFSET_UNKNOWN)
         {
            Console.WriteLine(" Native Offset: {0}", 
               sf.GetNativeOffset());
         }
      }
      Console.WriteLine();
      Console.WriteLine("   ... throwing exception to next level ...");
      Console.WriteLine("-------------------------------------------------\n");
      throw e;
   }
}
开发者ID:.NET开发者,项目名称:System.Diagnostics,代码行数:45,代码来源:StackFrame

示例5: ClassLevel5

try 
{
   ClassLevel5 nestedClass = new ClassLevel5();
   nestedClass.Level5Method();
}
catch (Exception e) 
{
   Console.WriteLine(" Level4Method exception handler");

   // Build a stack trace from a dummy stack frame.
   // Explicitly specify the source file name, line number
   // and column number.
   StackTrace st = new StackTrace(new StackFrame("source.cs", 79, 24));
   Console.WriteLine(" Stack trace with dummy stack frame: {0}", 
                  st.ToString());

   // Access the StackFrames explicitly to display the file
   // name, line number and column number properties.
   // StackTrace.ToString only includes the method name. 
   for(int i =0; i< st.FrameCount; i++ )
   {
      StackFrame sf = st.GetFrame(i);
      Console.WriteLine(" File: {0}", sf.GetFileName());
      Console.WriteLine(" Line Number: {0}", 
         sf.GetFileLineNumber());
      Console.WriteLine(" Column Number: {0}", 
         sf.GetFileColumnNumber());
   }
   Console.WriteLine();
   Console.WriteLine("   ... throwing exception to next level ...");
   Console.WriteLine("-------------------------------------------------\n");
   throw e;
}
开发者ID:.NET开发者,项目名称:System.Diagnostics,代码行数:33,代码来源:StackFrame


注:本文中的System.Diagnostics.StackFrame.StackFrame构造函数示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。