Question: I have a method that returns a `List`. Now I want to know how to place the `try/catch` blocks properly. If I place the `return` statement inside `try` I get error

> 
> Not all code paths return a value
> 
> 
> 

If I place after `catch`(like I'm doing currently) it will return the `products` even after an `Exception`. So what should be the best way?

Here is the method:

```
public List<Product> GetProductDetails(int productKey)
{
    List<Product> products = new List<Product>();
    try
    {
       using (SqlConnection con = new SqlConnection(_connectionString))
       {
         SqlCommand cmd = new SqlCommand("usp_Get_ProductDescription", con);
         cmd.CommandType = CommandType.StoredProcedure;
         cmd.Parameters.AddWithValue("@riProductID", productKey);
         con.Open();
         using (SqlDataReader reader = cmd.ExecuteReader())
         {
           while (reader.Read())
           {
             Product product = new Product(reader["Name"].ToString(), reader["Code"].ToString());
             products.Add(product);
           }
         }
       }
     }
     catch { }
     return products;
}

```

Answer: 
That depends on what should happen in an exceptional case. If this might happen for some reason which isn´t "bad enough" to let the app crash or if you are able to handle that exception appropriately then you might go with your current appraoch - however you should definitly leave at least a log-message within the catch-clause that contains the error which has been thrown:

```
catch (Exception e) 
{ 
    log.Info(e.Message);
}

```

This way you get all results within your list except those that caused any exceptions. You can simply continue work with all the results that you got and ignore those errorous (supposing you logged them in any way).

If it is a really unexpected behaviour (which is the intended one for exceptions, this is why they are called exceptions) you should delete all this try/catch from within your method and handle any exceptions outside the method as Maurice already mentioned.
At the moment, you don't return anything if an exception is thrown.
Use `try, catch, finally`. (May you want to see the [MSDN page](https://msdn.microsoft.com/en-us/library/dszsf989.aspx) for more official information)

```
try
{
    //try to execute this code
}
catch
{
    //execute this if an exception is thrown
}
finally
{
    //execute this code, after try/catch
}

```

So if you place your `return` statement into the `finally` section, you will return your list even if there's an exception thrown...