Skip exception

Skip exception

hi all ! I have the following code that returns a bool value. If there is no connection it should be false. The problem is that I always get the exception and get out of the program. Is there a way to avoid it?

  1.  private static bool IsMariaDBServer(string computerName)
  2.      {
  3.          Debug.WriteLine($"IsMariaDBServer on: {computerName}");

  4.          string connectionString = $"Server={computerName};Database={database};User Id={userId};Password={password};License Key={License};charset={Charset}";

  5.          try
  6.          {
  7.              using (MySqlConnection conn = new MySqlConnection(connectionString))
  8.              {
  9.                  conn.Open(); // Attempt to open a connection
  10.                  using (MySqlCommand cmd = new MySqlCommand("SELECT VERSION()", conn))
  11.                  {
  12.                      string version = cmd.ExecuteScalar()?.ToString();
  13.                      Console.WriteLine($"Connected to MariaDB on {computerName}, Version: {version}");
  14.                  }
  15.              }
  16.              return true; // Connection succeeded
  17.          }
  18.          catch
  19.          {
  20.              // Suppress the exception and log it if needed for debugging purposes
  21.              Console.WriteLine($"Connection failed for {computerName}");
  22.              return false; // Return false for any connection failure
  23.          }
  24.      }
Any help is appreciated.