title: catching va_list error
body: <p>I'm currently using the below function to print my debug strings:</p>
  
  <pre><code>void Script::OutputDebugStringN(const char *format, ...)
  {
      char outstring[256];
      memset(outstring, 0, sizeof(outstring));
  
      try
      {
          va_list args = {0};
          va_start(args, format); //args = (va_list) (&amp;format+1);
  
          vsprintf(outstring, format, args);
  
          va_end(args);
  
          OutputDebugString(outstring);
      }
      catch (...) //most likely reference val arg error (va_list doesn't support ref args)
      {
          OutputDebugString("[OutputDebugStringN] Something went wrong\n");
      }
  }
  </code></pre>
  
  <p>I receive a "An unhandled exception of type 'System.AccessViolationException' occurred in Editor.exe" error message each time I send in a reference value argument; which is completely understandable, but I'm wondering how I could encapsulate this in a possible try catch statement to prevent the error from shutting down my entire program. (the above does not work)</p>
  
  <p>I'm currently calling a self-made c++ dll (with the above function) from my c# editor. </p>
  
  <p>Here's the c# code:</p>
  
  <pre><code>private void ComponentDispatcher_ThreadIdle(object sender, EventArgs e)
      {
          //render display window (if something is not blocking it)
          if (renderViewHost.Update)
          {
              try { NativeMethods.UpdateRenderWindow(); }
              catch (Exception exc)
              { Debug.WriteLine("[ThreadIdle::UpdateRenderWindow] Exception caught: {0}" + exc); }
          }
      }
  </code></pre>
  
  <p>I just find it unacceptable that my function to print out my debug strings has in itself an error. Any ideas? All comments on bad code/observation are welcomed.</p>