C#C
C#2y ago
SoFt

Weirdest problem - catch doesnt work

c#
try
{
    using (var connection = new MySqlConnection("Server=x;Port=3306;Database=x;Uid=x;Pwd=x;Pooling=true"))
    {
        await connection.OpenAsync();
    }
}
catch(Exception ex)
{
    var q2 = "";
}



x is actually my server's info
If my server is running, this works ok. But if I reboot my server, this code throws unhandled exception! Basically catch doesnt work!

```System.AggregateException
  HResult=0x80131500
  Message=One or more errors occurred. (Timeout expired.  The timeout period elapsed prior to completion of the operation or the server is not responding.)
  Source=System.Private.CoreLib
  StackTrace:
   at System.Threading.CancellationTokenSource.ExecuteCallbackHandlers(Boolean throwOnFirstException) in /_/src/libraries/System.Private.CoreLib/src/System/Threading/CancellationTokenSource.cs:line 831
   at System.Threading.TimerQueueTimer.Fire(Boolean isThreadPool) in /_/src/libraries/System.Private.CoreLib/src/System/Threading/Timer.cs:line 683
   at System.Threading.TimerQueue.FireNextTimers() in /_/src/libraries/System.Private.CoreLib/src/System/Threading/Timer.cs:line 331
   at System.Threading.ThreadPoolWorkQueue.Dispatch() in /_/src/libraries/System.Private.CoreLib/src/System/Threading/ThreadPoolWorkQueue.cs:line 913
   at System.Threading.PortableThreadPool.WorkerThread.WorkerThreadStart() in /_/src/libraries/System.Private.CoreLib/src/System/Threading/PortableThreadPool.WorkerThread.NonBrowser.cs:line 102

Inner Exception 1:
MySqlException: Timeout expired.  The timeout period elapsed prior to completion of the operation or the server is not responding.

Inner Exception 2:
TimeoutException: The operation has timed out.
```

How is this possible?
Was this page helpful?