title: Catching multiple exceptions in console app using one try{...}catch{...} block
body: <p>I would like ask you to explain me how the exception system works in the following piece of code:</p>
  
  <pre><code>    static void Main(string[] args)
      {
          try
          {
              //Code which throws exceptions from time to time and runs in a loop
          }
          catch (Exception ex)
          {
              Console.WriteLine(ex.ToString());
          }
          Console.ReadKey();
      }
  </code></pre>
  
  <p>I noticed something which surprised me. When an exception is thrown, the code inside try{...} block is still running and can throw even more exceptions which will be printed to the console window.
  Shouldn't the code inside the loop finish its execution and "jump" to Console.ReadKey() at the end?</p>
  
  <p>@EDIT:</p>
  
  <p>The code inside is complicated and it would take a few pages. I can tell you that I make multiple asynchronous operations inside like downloading files, receiving packets, etc. In other words there are other threads which are created in the loop.</p>
  
  <p>@EDIT2:
  Presumably this is the code responsible for the behavior:</p>
  
  <pre><code>public SomeConstructor(Socket server)
      {
          _pb = new PacketBuilder(server, c);
  
          SocketWrapper sw = new SocketWrapper(server, Globals.recvBufferSize);
          sw.Socket.BeginReceive(sw.Buffer, 0, Globals.recvBufferSize, SocketFlags.None,PacketReceiveCallback, sw);
  
          _pi = new PacketInterpreter(this, c);
      }
  
      private void PacketReceiveCallback(IAsyncResult iar)
      {
          SocketWrapper sw = iar.AsyncState as SocketWrapper;
          int bytesReceived = sw.Socket.EndReceive(iar);
  
          _pi.Interpret(sw.Buffer, 0, bytesReceived);
  
          if (bytesReceived &gt; 0)
              sw.Socket.BeginReceive(sw.Buffer, 0, Globals.recvBufferSize, SocketFlags.None, PacketReceiveCallback, sw);
      }
  </code></pre>