title: How to handle ibm.data.db2.iseries exceptions
body: <p>I have this code:</p>
  
  <pre><code>con = new iDB2Connection(connectString);
  try { con.Open(); }
  catch (iDB2ConnectionTimeoutException ex)
  { Console.WriteLine(ex.Message); }
  catch (iDB2DCFunctionErrorException ex)
  { Console.WriteLine(ex.Message); }
  catch (AccessViolationException ex)
  { Console.WriteLine(ex.Message); }
  </code></pre>
  
  <p>Close connection</p>
  
  <pre><code>if (con != null)
  {
              try
              {
                  Console.WriteLine("CRASH IS AFTER THIS");
                  if (con.State != ConnectionState.Closed)
                  {
                      con.Close();
                  }
              }
  
              catch (iDB2ConnectionTimeoutException ex)
              {
                  Console.WriteLine(ex.Message);
              }
              catch (iDB2DCFunctionErrorException ex)
              {
                  Console.WriteLine(ex.Message);
              }
              catch (AccessViolationException ex)
              {
                  Console.WriteLine(ex.Message);
              }
              catch (iDB2Exception ex)
              {
                  Console.WriteLine(ex.Message);
              }
              catch (Exception ex)
              {
                  Console.WriteLine(ex.Message);
              }
              finally
              {
  
              }
          }
  </code></pre>
  
  <p>But I still get this nasty message when the Close connection is being run:</p>
  
  <pre><code>    Unhandled Exception: IBM.Data.DB2.iSeries.iDB2DCFunctionErrorException: An unexp
  ected exception occurred.  Type: System.AccessViolationException, Message: Attem
  pted to read or write protected memory. This is often an indication that other m
  emory is corrupt.. ---&gt; System.AccessViolationException: Attempted to read or wr
  ite protected memory. This is often an indication that other memory is corrupt.
     at IBM.Data.DB2.iSeries.CwbDc.DcDnIsAlive(Int32 functionNumber, IntPtr connec
  tionHandle, IntPtr nullParm)
     at IBM.Data.DB2.iSeries.MPConnection.IsAlive()
     --- End of inner exception stack trace ---
     at IBM.Data.DB2.iSeries.MPConnection.IsAlive()
     at IBM.Data.DB2.iSeries.MPConnectionManager.GetConnection(iDB2Connection piDB
  2Connection)
     at IBM.Data.DB2.iSeries.iDB2Connection.Open()
  </code></pre>
  
  <p>I get this when I know the iSeries is down for maintenance.<br>
  How do I handle this so that the C# console application continues on?</p>