Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
CPU resources used by try-catch blocks
Message
From
20/05/2004 07:50:22
 
 
To
19/05/2004 17:04:11
General information
Forum:
ASP.NET
Category:
Other
Miscellaneous
Thread ID:
00905386
Message ID:
00905550
Views:
16
Nancy,

I think this is more of a general description of managed exceptions.

If you take the example of unmanaged code through P/Invoke then there are extra steps involved between SEH and managed EH ie. the exception is caught then translated to an appropriate managed exception and rethrown. This essentially means the CLR is dealing within/between two exception handling mechanisms and one would assume as with the general use of interop. there may be extra overhead in doing this.

The following source and IL illustrates the exception tables (only one in this example) and where they appear in relation to the methods IL code (straight after).
using System;

namespace ConsoleApplication1
{
   /// <summary>
   /// Summary description for Class1.
   /// </summary>
   class Class1
   {
      /// <summary>
      /// The main entry point for the application.
      /// </summary>
      [STAThread]
      static void Main(string[] args)
      {
         object objTest1 = null;

         try
         {
            int intTest1 = (int) objTest1;
         }
         catch (NullReferenceException e) 
         {
            Console.WriteLine(e.Message);
         }
      }
   }
}
.namespace ConsoleApplication1
{
  .class /*02000002*/ private auto ansi beforefieldinit Class1
         extends [mscorlib/* 23000001 */]System.Object/* 01000001 */
  {
    .method /*06000001*/ private hidebysig static 
            void  Main(string[] args) cil managed
    {
      .entrypoint
      .custom /*0C000001:0A00000E*/ instance void [mscorlib/* 23000001 */]System.STAThreadAttribute/* 0100000F */::.ctor() /* 0A00000E */ = ( 01 00 00 00 ) 
      // Code size       27 (0x1b)
      .maxstack  2
      .locals /*11000001*/ init ([0] object objTest1,
               [1] int32 intTest1,
               [2] class [mscorlib/* 23000001 */]System.NullReferenceException/* 01000013 */ e)
      IL_0000:  ldnull
      IL_0001:  stloc.0
      IL_0002:  ldloc.0
      IL_0003:  unbox      [mscorlib/* 23000001 */]System.Int32/* 01000010 */
      IL_0008:  ldind.i4
      IL_0009:  stloc.1
      IL_000a:  leave.s    IL_001a

      IL_000c:  stloc.2
      IL_000d:  ldloc.2
      IL_000e:  callvirt   instance string [mscorlib/* 23000001 */]System.Exception/* 01000011 */::get_Message() /* 0A00000F */
      IL_0013:  call       void [mscorlib/* 23000001 */]System.Console/* 01000012 */::WriteLine(string) /* 0A000010 */
      IL_0018:  leave.s    IL_001a

      IL_001a:  ret
      IL_001b:  
      // Exception count 1
      .try IL_0002 to IL_000c catch [mscorlib/* 23000001 */]System.NullReferenceException/* 01000013 */ handler IL_000c to IL_001a
    } // end of method Class1::Main

    .method /*06000002*/ public hidebysig specialname rtspecialname 
            instance void  .ctor() cil managed
    {
      // Code size       7 (0x7)
      .maxstack  1
      IL_0000:  ldarg.0
      IL_0001:  call       instance void [mscorlib/* 23000001 */]System.Object/* 01000001 */::.ctor() /* 0A000011 */
      IL_0006:  ret
    } // end of method Class1::.ctor

  } // end of class Class1
I think this illustrates how easy the CLR makes exception handling wether working with unmanaged/managed, however, I don't think all scenario's have the same runtime cost associated with them.

Regards
Neil
Previous
Next
Reply
Map
View

Click here to load this message in the networking platform