title: How to access the Exception variable more than once in an injected try catch handler with Mono.Cecil?
body: <p>I am adding a try catch block surrounding the method body using Mono.Cecil</p>
  
  <p>All is going well, even I can call a method with the caught Exception exception1 parameter in the catch block, as it seems the exception1 value is on top of the stack. </p>
  
  <p>However after the call the value is removed from the stack, and if I would like to call an other method with the exception1 as parameter I can not figure out how to access it an ldloc before the call.</p>
  
  <p>So the following code is working, I just do not know how to call an other method in the catch block with the caught exception value as parameter.</p>
  
  <pre><code>var statementInTheCatchBlock = il.Create(OpCodes.Call, module.Import(typeof(AnyType).GetMethod("AnyMethod", new[] { typeof(Exception) })));
  var ret = il.Create(OpCodes.Ret);
  var leave = il.Create(OpCodes.Leave, ret);
  
  il.InsertAfter(method.Body.Instructions.Last(), statementInTheCatchBlock);
  il.InsertAfter(statementInTheCatchBlock, leave);
  il.InsertAfter(leave, ret);
  
  var handler = new ExceptionHandler(ExceptionHandlerType.Catch)
  {
      TryStart = method.Body.Instructions.First(),
      TryEnd = statementInTheCatchBlock,
      HandlerStart = statementInTheCatchBlock,
      HandlerEnd = ret,
      CatchType = module.Import(typeof(Exception)),
  };
  method.Body.ExceptionHandlers.Add(handler);
  </code></pre>
  
  <p>Thx in advance</p>