StackTrace::FrameCount Property

 

Gets the number of frames in the stack trace.

Namespace:   System.Diagnostics
Assembly:  mscorlib (in mscorlib.dll)

public:
property int FrameCount {
	virtual int get();
}

Property Value

Type: System::Int32

The number of frames in the stack trace.

The following code example displays the first and last function calls in a stack trace.

void Level5Method()
{
   try
   {
      ClassLevel6^ nestedClass = gcnew ClassLevel6;
      nestedClass->Level6Method();
   }
   catch ( Exception^ e ) 
   {
      Console::WriteLine( " Level5Method exception handler" );
      StackTrace^ st = gcnew StackTrace;

      // Display the most recent function call.
      StackFrame^ sf = st->GetFrame( 0 );
      Console::WriteLine();
      Console::WriteLine( "  Exception in method: " );
      Console::WriteLine( "      {0}", sf->GetMethod() );
      if ( st->FrameCount > 1 )
      {

         // Display the highest-level function call
         // in the trace.
         sf = st->GetFrame( st->FrameCount - 1 );
         Console::WriteLine( "  Original function call at top of call stack):" );
         Console::WriteLine( "      {0}", sf->GetMethod() );
      }
      Console::WriteLine();
      Console::WriteLine( "   ... throwing exception to next level ..." );
      Console::WriteLine( "-------------------------------------------------\n" );
      throw e;
   }

}

.NET Framework
Available since 1.1
Silverlight
Available since 2.0
Windows Phone Silverlight
Available since 7.0
Return to top
Show: