title: using try-catch in .net structure constructor
body: <p>I have need of a .net structure (it mimics a connected devices internal map) and I want to use a try catch block since I'm using Marshall.PtrToStructure() and associated GChandle stuff. However I when I put the structures field assignments inside the try catch block I get this error "field1 must be fully assigned before control is returned to sender". The basic code works fine without the try catch block. Is there any way around this error while using try catch blocks? Should I use try catch?</p>
  
  <pre><code>[StructLayout( LayoutKind.Sequential )]
  public struct Effects
  {
      public UInt16 field_1;
      public UInt16 field_2;
      ...
  
  
  
      public Effects(byte[] effectsData)
      {
         GCHandle gch;
         try
         {
             gch = GCHandle.Alloc( effectsData, GCHandleType.Pinned );
             IntPtr pEffects = gch.AddrOfPinnedObject( );
             this = (Effects)Marshal.PtrToStructure( pEffects, typeof(Effects ) );
         }
         catch (Exception ex)
         {
  
         }
         finally
         {
             if (gch.IsAllocated)
                 gch.Free( );
         }
      }
  }
  </code></pre>